# Write an algorithm for the implementation of a Circularly Doubly Linked List.

, ,

#include<stdio.h>

/* Structure declaration */
{
int number;
};

/* Global variable declaration */

/* Global functions declaration */
void insertNode(int n);
void deleteNode(int n);
void displayList();

/* main( ) function */
void main()
{
int choice, num;
while(1)
{
printf("\n Press 1 for insert number");
printf("\n Press 2 for delete number");
printf("\n Press 3 for display list");
printf("\n Press 4 for exit");
printf("\n Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n Enter the number : ");
scanf("%d",&num);
insertNode(num);
break;
case 2:
printf("\n List is blank !");
else
{
printf("\n Enter the number : ");
scanf("%d",&num);
deleteNode(num);
}
break;
case 3:
displayList();
break;
case 4:
exit(0);
default:
printf("\n\n\n Wrong Input");
}
}
}

/* Insert number into the list */
void insertNode(int n)
{
/* Check whether the list is blank or not */
/* If blank then create a memory into head variable and place the number into it */
{
}
else
{
/* If the list is not blank then create a memory into temp variable, place the number into it and add this memory to the end of the list */
temp = (NODE *) malloc(sizeof(NODE));
temp->number = n;
p = p->next;
p->next = temp;
temp->previous = p;
}
}

/* Delete a particular number from the list */
void deleteNode(int n)
{
int found = 0;
/* Check whether the list contain only one element or not */
{
{
found = 1;
}
}
else
/* Check whether the number found into the first-memory (head) of the list or not ? */
{
found = 1;
}
else
{
{
if(p->number == n)
{
p->next->previous = p->previous;
p->previous->next = p->next;
found = 1;
break;
}
p = p->next;
}
}
if(found == 0)
}

/* Display list elements */
void displayList()
{
/* Check whether the list is blank or not */
printf("\n List is blank !");
else
{