C Program to Reverse LinkedList

LinkedList
Linked list is a data structure, contains the reference(link) of next record in a sequence

  1. LinkedList is a Dynamic Datastructre, It grows and shrinks during runtime
  2. Insertion and deletion operations are easier and faster
  3. Efficent, Memory Utilization, i,e No need to preallocate Memory
  4. Linear Data Structure such as Stack, Queue can be implemented using LinkedList

C Program to Reverse Single Linked List

reverse(struct node **x)
{
   Struct node *q, *r, *s;
   *q=*x;
   r=NULL;
   while(q!=NULL)
   {
      s=r;
      r=q;
      q=q->link;
      r->link=s;
   }
*x=r;
}

 C Program to Reverse Double LinkedList

void reverse(struct node **head_ref)
{
   struct node *temp = NULL;
   struct node *current = *head_ref;
   while (current != NULL) {
      temp = current->prev;
      current->prev = current->next;
      current->next = temp;
      current = current->prev;
   }
if(temp != NULL )
*head_ref = temp->prev;
}

About mohan

This is Mohan Jayapalan author of TechPages Blog.I am a part time blogger and Currently working for private Software Concern.

© Copyright 2010-2016 www.techpages.org · All Rights Reserved · Powered by WordPress ·