i insert 10 as first location then 20 and 30
when i run the program it give me error in location
10 30 20
the error may be in insert can you give me hints for this
thank you in advance
Expand|Select|Wrap|Line Numbers
- Node * List::InsertNode (int index , double x)
- {
- if (index < 0 )return NULL;
- int currlndex = 1 ;
- Node* currNode = head;
- while (currNode!= NULL && index > currlndex )
- {
- currNode;
- currlndex++;
- }
- if (index > 0 && currNode == NULL ) return NULL;
- Node*newNode = new Node;
- newNode -> data = x;
- if (index ==0)
- {
- newNode -> next = head;
- head = newNode;
- }
- else
- {
- newNode -> next = currNode->next;
- currNode->next = newNode ;
- }
- return newNode;
- }