#include<stdio.h>
#include<conio.h>
#include<malloc.h>
int pos,i,n,item;
struct doubly
{
int data;
struct doubly *pre, *next;
}; struct doubly *head, *tail, *temp, *temp1, *temp2, *nw;
void insert_b()
{
int item;
clrscr();
printf("Enter Item : ");
scanf("%d",&item);
nw = (struct doubly *)malloc(sizeof(struct doubly));
nw -> data = item;
nw -> pre = NULL;
nw -> next = head;
head ->pre = nw;
head = nw;
}
void insert_e()
{
int item;
clrscr();
printf("Enter Item : ");
scanf("%d",&item);
while(temp->next != NULL)
{
temp = temp -> next;
}
nw = (struct doubly *)malloc(sizeof(struct doubly));
nw -> data = item;
temp -> next = nw;
nw ->pre = temp;
temp = nw;
nw ->next = NULL;
}
void insert_m()
{
temp1=head;
temp2=head;
clrscr();
printf("Enter Your Position : ");
scanf("%d",&pos);
printf("Enter Item : ");
scanf("%d",&item);
for(i=1;i next;
}
temp2=temp1 -> next;
nw = (struct doubly *)malloc(sizeof(struct doubly));
nw -> data = item;
temp1 -> next = nw;
nw -> next = temp2;
temp2 -> pre = nw;
nw -> pre = temp1;
}
void delete_b()
{
clrscr();
temp = head;
head = head ->next;
printf("%d is deleted.",temp->data);
free(temp);
head -> pre = NULL;
getch();
}
void delete_e()
{
clrscr();
temp = head;
while(temp->next->next != NULL)
{
temp =temp->next;
}
printf("%d is deleted.",temp->next->data);
free(temp->next);
tail = temp;
temp -> next = NULL;
getch();
}
void delete_m()
{
clrscr();
temp1 = head;
temp2 = head;
printf("Enter Positon : ");
scanf("%d",&pos);
for(i=1;inext;
}
temp2 = temp1 -> next;
temp1->next = temp2->next;
printf("%d position %d is deleted.",pos,temp2->data);
free(temp2);
temp1->next->pre = temp1 ->next;
getch();
}
void display()
{
temp= head;
while(temp->next!= NULL)
{
printf("\n\t%d",temp->data);
temp= temp->next;
}
printf("\n\t%d",temp->data);
}
void main()
{
int item,ch;
do
{
clrscr();
printf("1. Insert Node of Beginning : \n2. Insert Node of middle any Posistion\n3. Insert Node of Ending : \n4. Delete Node of Beginning\n5. Delete Node of middle any position\n6. Delete Node of Ending\n7. Display\n8. Exit\n\n ");
printf("Enter Your Choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert_b();
break;
case 2:
insert_m();
break;
case 3:
insert_e();
break;
case 4:
delete_b();
break;
case 5:
delete_m();
break;
case 6:
delete_e();
break;
case 7:
clrscr();
display();
getch();
break;
case 8:
printf("Thank U");
break;
}
}while(ch != 8);
}