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
#ifndef NUMBERLIST_H
#define NUMBERLIST_H

class NumberList
{
private:
    // 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

public:
    // Constructor
    NumberList()
    { head = NULL; }

    // Destructor
    ~NumberList();

    // 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;

};
#endif



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

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

    first = head_ref;
    rest  = first->next;

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

    /* 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;
}

Recommended Answers

All 8 Replies

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 ;

    while(temp!=NULL)
    {
        if(temp->data == num)
            return(temp); //Found
        temp = temp -> next;
    }

    if(flag == 0)
        return(value); // Not found
}

Is that all the code?

yes for rev and secrach.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.