Function to reverse a linked list

struct node *reverse(struct node *start)
{
	struct node *previous, *ptr, *next;
	previous = NULL;
	ptr = start;
	
	while(ptr!=NULL)
        {
                        next=ptr->link;
                        ptr->link=previous;
                        previous=ptr;
                        ptr=next;
        }
        start=previous;
        return start;
}
Previous Post
Linked list search function
Next Post
Stack using linked list

Related Posts

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Menu