0% found this document useful (0 votes)
35 views1 page

2.rotate K

The function rotates a linked list by k nodes, where k is the number of rotations. It takes the head of the linked list and k as parameters. It sets the next pointer of the last node to the head, moves the head k nodes ahead, and sets the next of the new last node to null.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views1 page

2.rotate K

The function rotates a linked list by k nodes, where k is the number of rotations. It takes the head of the linked list and k as parameters. It sets the next pointer of the last node to the head, moves the head k nodes ahead, and sets the next of the new last node to null.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

struct node

{
int data;
struct node *next;
}
*/
void rotate(struct node **h, int k)
{
if(h==NULL)
return ;
node *c=*h,*temp;
for(int i=1;i<=k;i++)
{
c=head;
temp=head;
while(c->next!=NULL)
{
c=c->next;
}
c->next=temp;
head=head->next;
temp->next=NULL;
}
}

You might also like