#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void insert_last(int val);
int del_last();
void show();
void insert();
struct dll
{
struct dll *prev;
int info;
struct dll *next;
}*s,*e,*temp,*i;
void main()
{
int choice,val;
char ch;
insert();
do{ printf("\t\t***********************MENU*****************\n");
printf("\t\t1-For insert node at end of doubly link list:\n");
printf("\t\t2-For delete last node in doubly link list:\n");
printf("\nEnter choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
printf("\nEnter a no you want to insert:");
scanf("%d",&val);
insert_last(val);
show();
break;
}
case 2:
{
val=del_last();
printf("\ndeleted element :%d\n",val);
printf("now updated list:\n");
show();
break;
}
}
printf("you want to continue Y/N..? ");
flushall();
scanf("%c",&ch);
}while(ch=='y'||ch=='Y');
getch();
}
void insert()
{ clrscr();
printf("Enter node for link list\n");
temp=(struct dll*)malloc(sizeof (struct dll));
temp->next=temp->prev=NULL;
scanf("%d",&temp->info);
s=temp;
e=temp;
}
void insert_last(int val)
{
temp=(struct dll*)malloc(sizeof (struct dll));
temp->next=NULL;
temp->info=val;
e->next=temp;
temp->prev=e;
e=temp;
}
int del_last()
{
int val;
val=e->info;
temp=e;
e=e->prev;
e->next=NULL;
free(temp);
return(val);
}
void show()
{
for(i=s;i!=NULL;i=i->next)
printf("%d\n",i->info);
}