Function to reverse a Circular Doubly Linked List
A doubly linked list is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains two fields, called links, that are references to the previous and to the next node in the sequence of nodes.The structure of a node in a Doubly linked list is as given below.
struct node
{
struct node *Llink;
int data;
struct node *Rlink;
}
If we create the Doubly linked list in a circular fashion, it forms a Circular doubly linked list.
The function "reverse" reverses a circular doubly linked list with the head node given.
void swap(struct node *p,struct node *q)
{
struct node *r;
r = p;
p = q;
q = r;
}
void reverse(struct node *head)
{
struct node *t = head -> Rlink;
while(t != head)
{
swap(t -> Llink, t ->Rlink);
t = t -> Llink;
}
swap(head -> Llink, head -> Rlink)
}
Written by Munia Balayil
No comments:
Post a Comment