Skip to content

Instantly share code, notes, and snippets.

@Nimishkhurana
Created October 15, 2019 07:39
Show Gist options
  • Save Nimishkhurana/3048a38a78d0b543246ebbbc78e92276 to your computer and use it in GitHub Desktop.
Save Nimishkhurana/3048a38a78d0b543246ebbbc78e92276 to your computer and use it in GitHub Desktop.
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