remove node from double linked list class

Hey guys
I am really beginner of c++. My teacher ask me to write a function to remove node from double linked list class, giving by the value which want to be removed. It is also a friend function of the class(don't know if this make any differences). I really have no idea about this. The class definition is as below. Please help me out. Thank you so much!

class Node
{
public:
Node(int value, Node *Nodep1, Node *Nodep2)
{
data = value;
Next = Nodep1;
Last = Nodep2;
}
void setLast(Node * last_node)
{
Last = last_node;
}
void setNext(Node * next_node)
{
Next = next_node;
}
Node * getNext ()
{
return Next;
}
Node * getLast ()
{
return Last;
}

private:
int data;
Node * Last;
Node * Next;
};
typedef Node* Np;
Last edited on
does that class definition even compile, considering there are 2 definitions of value(one as a private variable and one in the constructor of Node), and no definition of data(used in 2nd line of node)?

what you want to do is to
1. start at the first node of the the linked list
2. check if it contains the the value you want to delete
3. if not, check the node after that to see if it contains the value.
4. repeat steps 2 and 3 until you find the value
5. when you find the value, Node.getNext() -> setlast( element.getlast() );
6. and Node.getLast() -> setNext(element.getNext());
7. and then delete the said node

*I hope that was right...
-blueberry
Topic archived. No new replies allowed.