Created
October 15, 2019 07:39
-
-
Save Nimishkhurana/3048a38a78d0b543246ebbbc78e92276 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node *reverse(struct node *head, int k) | |
{ | |
node* curr=head, *prev=NULL, *last=NULL; | |
while(curr){ | |
int count=0; | |
node *h = curr; | |
// h->next=NULL; | |
while(curr && count<k){ | |
node* next = curr->next; | |
curr->next = prev; | |
prev=curr; | |
curr=next; | |
if(next) | |
next = next->next; | |
count++; | |
} | |
if(!last){ | |
head = prev; | |
} | |
else{ | |
last->next = prev; | |
} | |
last = h; | |
prev = NULL; | |
} | |
return head; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment