1.

Write an algorithm to reverse a singly linked list. 

Answer»

The algorithm to reverse a singly link list is as follows:-

reverse (struct node **st) 

{

struct node *p, *q, *r;

p = *st;

q = NULL;

while (p != NULL)

{

r =q;

q = p;

p = p link;

 link = r; 

}

*st = q;

}



Discussion

No Comment Found

Related InterviewSolutions