Which errors you get?
two things I've seen:
- in appendNode Node* newnode;
-> newnode is just setted and never used (it's not an error but you
can erase it)
- I'm not sure but I think for nodeptr->next = new Node();
you need a constructor and later a destructor in public part of Node class
Last edited on
- In void List::appendNode(int num)
method, you need to allocate memory for the new node, even for the first one (head) :
Node* newnode = new Node();
instead of Node* newnode;
- Then, you have a classical test error (assignment instead of equality test) :
if(head=NULL)
should be if(head==NULL)
- And finally, you can use the previously created/allocated newnode variable :
nodeptr->next = newnode;
instead of nodeptr->next = new Node();
You can comment //nodeptr->next->data = num;
. It's no use then ... You previously set data for newnode.