I have come up with this approch for this question… But it is not showing any output…
Can you see this
Not showing any output
Ashish, you can use the following approach for the k append function 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;
}
Can you please show where my code is wrong… i think i have implemented correct way…
Like atleast it should show output for smaller test cases
I have modefied my code… it is printing correct for some test cases and not for some… https://ide.codingblocks.com/s/315485 can you point me out where my code fails.
Ok, I will let u know…
I have edited your code, basically you need to take a mod value of k and then :
(if k==0)
{
print(head);
}
else
{
append();
print(head);
}
}
I have made the changes. Pls refer to the code,