K append : plz check why back pointer does'nt move?
Ashish, the approach you are using in your code is not correct. Kindly follow the approach as :
node* append(node*&head,int k)
{
nodeslow=head;
nodefast =head;
node *oldHead=head;
for(int i=0;i<k && fast->next!=NULL ; i++)
{
fast=fast->next;
}
while(fast->next!=NULL && fast!=NULL)
{
fast=fast->next;
slow=slow->next;
}
node *newHead=slow->next;
slow->next=NULL;
fast->next=oldHead;
return newHead;
}
Ashish, the https://ide.codingblocks.com/s/292668 is partially correct… I have made relevant changes in that code…Pls refer to this code and try to submit now…
https://ide.codingblocks.com/s/317327
The code https://ide.codingblocks.com/s/292689 is not the correct approach, since in the linked list question, it is always advisable to make changes in the original linked list …