Sykora
I see right through you.
Re: Post ur C/C++ Programs Here
The only way is to create a new list, going through each node of the previous list and inserting it at the beginning of the new list.
eg :
Now you have a new list, with revHead as the head node.
The only way is to create a new list, going through each node of the previous list and inserting it at the beginning of the new list.
eg :
Code:
Node *p = head->next;
Node *revHead = head;
head = head->next;
revHead->next = NULL;
while (p != NULL) {
p = p->next;
head->next = revHead;
revHead = head;
head = p;
}
Now you have a new list, with revHead as the head node.