/*****
Moving Last node to the front of linked list
movelastnodetofront()
*****/
// Lets have two pointer (p,q) one will be one step ahead of other;
// the moment one pointer (p) reaches last node ; point its link to head,
// and put null into q ;
movelastnodetofront()
{
struct node *p,*q;
p=head;
while(p->link != NULL)
{
q=p;
p=p->link;
}
q->link= NULL;
p->link=head;
head=p;
}
Moving Last node to the front of linked list
movelastnodetofront()
*****/
// Lets have two pointer (p,q) one will be one step ahead of other;
// the moment one pointer (p) reaches last node ; point its link to head,
// and put null into q ;
movelastnodetofront()
{
struct node *p,*q;
p=head;
while(p->link != NULL)
{
q=p;
p=p->link;
}
q->link= NULL;
p->link=head;
head=p;
}
No comments:
Post a Comment