A journal for curious minds & hands-on builders.

Follow Marxtudor

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 story
Next story

Join the conversation.

Leave a Reply

Your email address will not be published. Required fields are marked *

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