Hey, I was playing with code and found something
node* reverse(node*head){
if(head->next == NULL|| head == NULL){
return head;
}
node* smallHead = reverse(head->next);
node *c = head;
c->next->next = c;
c->next = NULL;
return smallHead;
}
how/Why above is different from
node* reverse(node*head){
if(head->next == NULL|| head == NULL){
return head;
}
node* smallHead = head->next;
reverse(smallHead);
node *c = head;
c->next->next = c;
c->next = NULL;
return smallHead;
}
You can test it here https://ide.codingblocks.com/s/61422
Why they are different?
@sanjeetboora
@Khushboo
They both show different output.