Slideshow

Monday, 25 February 2013


Write an algorithm to reverse a singly linked list. 

Ans:
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;
q  link = r;
}
*st = q;

No comments:

Post a Comment