Question: WAP to reverse a linklist non-recursively.

Answer:

  
void reverse (struct list **list1)
{
struct list *next, *cur, *tmp;
cur = *list1;
tmp=0;

if (!list1)
return;

while(cur)
{
next = cur->next;
cur->next=tmp;
tmp = cur;
cur = next;
}
*list1 = tmp;
}

Subscribe - To get an automatic feed of all future posts subscribe here, or to receive them via email go here and enter your email address in the box. You can also like us on facebook and follow me on Twitter @akashag1001.