I am to make a rev op on linked node but somehow i couldnt get to work. I got an error I am kinda stuck right now. The error is in gray

Somehow and somewhere doesnt show the reverse link. Can someone show how to do the search node like? I kiddan stuck at that. Can someone help me out thx

// Specification file for the NumberList class

class NumberList
    // Declare a structure for the list
    struct ListNode
        double value;           // The value in this node
        struct ListNode *next;  // To point to the next node

    ListNode *head;            // List head pointer

    // Constructor
    { head = NULL; }

    // Destructor

    // Linked list operations
    void appendNode(double);
    void insertNode(double);
    void reverseNode(double); // added the new node
    void searchNode (double); // added the new node
    void deleteNode(double);
    void displayList() const;


void NumberList::reverseNode(double num)
    struct ListNode* head_ref = NULL;
    struct ListNode* first;
    struct ListNode* rest;

    /* empty list */
    if (head_ref == NULL)

    first = head_ref;
    rest  = first->next;

    /* List has only one node */
    if (rest == NULL)

    /* reverse the rest list and put the first element at the end */
    reverseNode(*rest);  // <----- Got an ERROR here 
    first->next->next  = first;

    first->next  = NULL;

    /* fix the head pointer */
    *head_ref = *rest;

Edited by mike_2000_17: fixed formatting

2 Years
Discussion Span
Last Post by chubbyy.putto

What I am trying to say is: I am making a reverse linked node but i got error and I am stuck. I am also trying to do the search node dont know how


Your reverseNode function takes a double as a parameter.
But in your recursive call to reverseNode at line 56 you are dereferencing rest, which is declared as a pointer to a ListNode. So you are effectively passing a ListNode into the recursive call, NOT a double, which is what the compiler expects. Because it is not getting a double at that point, the compiler is displaying an error message.

Exactly what are you trying to do with your reverseNode function?
Are you trying to reverse the entire list? Or are you trying to do something else with it?


I am try to reverse the enitre list. Like print out the org. 1-2-3-4 and then reverse would be 4-3-2-1 and after that I have to do searchNode


here is my search function

void NumberList::searchNode (double num) // added the new node
    int flag = 0;
    struct ListNode *temp;

    temp = value ;

        if(temp->data == num)
            return(temp); //Found
        temp = temp -> next;

    if(flag == 0)
        return(value); // Not found
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.