kaiser
BAN USERvoid sort(struct node **base)
{
struct node *temp,*m,*n,*r;
temp=*base;
m=*base;
while( temp->link != NULL && temp->link->data > temp->data)
temp=temp->link;
n=temp->link;
if(m->data > n->data)
{
r=n;
n=n->link;
temp->link=n;
r->link=m;
*base=r;
m=*base;
}
while(m != n && n != NULL)
{
if(m->link->data > n->data)
{
r=n;
n=n->link;
temp->link=n;
r->link=m->link;
m->link=r;
}
m=m->link;
}
}
The above code works fine
e.g
Enter the no. of elements in linked list(n) and the reverse shift(k) and travel shift(m) such that [2<=k,m<=n] 26 3 5
Enter the elements : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
Output
3 2 1 4 5 6 7 8 11 10 9 12 13 14 15 16 19 18 17 20 21 22 23 24 26 25
}
- kaiser February 19, 2013