Can someone help me with this code..
I have a function which is InsertNode()
it is use for inserting a new node after the index in the
double link list..
For example I want to add a node of value 6.0 after position 3
This is the code i write..but It seems like wrong...
can someone help me...correcting this code..
Thnks so much..
Node* List::InsertNode(int index, double x)
{
if(index<0)
return NULL;
int currIndex=1;
Node* currNode=head;
while(currNode && index > currIndex)
{
currNode = currNode->next;
currIndex++;
}
if(index >0 && currNode==NULL)
return NULL;
Node* newNode = new Node;
newNode->data = x;
if(index==0)
{
newNode->next = head;
head->prev = newNode;
head = newNode;
newNode->prev = NULL;
}
else
{
newNode->next = currNode->next;
currNode->next->prev = newNode;
currNode->next = newNode;
newNode->prev = currNode;
}
return newNode;
}