// Circular Doubly Linked List Create and Display functions
#include <stdio.h>
#include<stdlib.h>
typedef struct Doubly
{
int val;
struct Doubly *next;
struct Doubly *prev;
} db;
void create(db**,db**);
void fwddisp(db*);
void bckdisp(db*);
int main()
{
db *head=NULL,*tail=NULL;
create(&head,&tail);
printf("\n\nForward Display : ");
fwddisp(head);
printf("\n\nBackward Display : ");
bckdisp(tail);
return 0;
}
void create(db **head,db **tail)
{
db *temp;
int g;
char ch;
while(1)
{
printf("\nEnter the value for the node : ");
scanf("%d",&g);
temp=(db*)malloc(sizeof(db));
temp->val=g;
temp->prev=temp->next=temp;
if(*head==NULL)
*head=*tail=temp;
else
{
(*tail)->next=temp;
temp->prev=*tail;
temp->next=*head;
*tail=temp;
(*head)->prev=*tail;
}
printf("Do u want more node (y/n) : ");
scanf(" %c",&ch);
if(ch=='n' || ch=='N')
break;
}
}
void fwddisp(db *head)
{
db *ptr=head;
while(ptr->next!=head)
{
printf("%d ",ptr->val);
ptr=ptr->next;
}
printf("%d",ptr->val);
}
void bckdisp(db *tail)
{
db *ptr=tail;
while(ptr->prev!=tail)
{
printf("%d ",ptr->val);
ptr=ptr->prev;
}
printf("%d",ptr->val);
}