Skip to content

Instantly share code, notes, and snippets.

@anandpathak
Created January 24, 2016 16:47
Show Gist options
  • Save anandpathak/2b72decb503aac7fcfb3 to your computer and use it in GitHub Desktop.
Save anandpathak/2b72decb503aac7fcfb3 to your computer and use it in GitHub Desktop.
Reversing linkedlist node recursively
//head points to the first node of the linked list
void reverse(struct node * ptr1){
struct node *ptr2;
if(ptr1->next !=NULL){
ptr2=ptr1->next;
reverse(ptr1->next);
temp=ptr2->next;
ptr2->next=ptr1;
ptr1->next=temp;
return ;
}
else{
head=ptr1;
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment