rev->next->next = NULL;
//this line has to be there.
//Else it wont work.
//Check it once.
//If we go for the recursive function then
//why don't you have two arguments? Try the below code?
OutputList = ReverseNew(LList,NULL); //Call should be like this.
Node* ReverseNew(Node *NList, Node * Remaining)
if(NList == NULL) return Remaining;
Node *tList = NList->Next;
NList->Next = Remaining;
*** If linked list is very big, then a big stack will be created for recursive function, may cause problem.
*** Need to think, as recursive will not be a better solution. :)
reverse using recursion..
i think this if condition is wrong
if (! (n && n -> next))
it should be
if (! (n->next && n->next->next))
this is to ensure that n points to the 2nd last node. (i.e. if n->next->next is NULL we have to return n as here n is pointing to the 2nd last node and we have to start reversing links from here)
because if you return the last node as per "if (! (n && n -> next))",
n->n->next = head will crash as n->next->next is NULL..since head is aldready pointing to the last node.
so we have to ensure that n is pointing to the 2nd last node.