Professional Documents
Culture Documents
Double LL
Double LL
h>
#include<conio.h>
#include<stdlib.h>
#define MAX 20
struct node
{
int data;
struct node*next;
struct node*prev;
};
struct node *head;
struct node *temp;
struct node *last;
//head=NULL;
//temp=NULL;
//last=NULL;
int m=0;
}
}
}
}
}
/*****************DELETION IN LINK LIST****************/
void delet()
{
int p=0,i=0;
if(head==NULL)
{
printf("\nLink list is empty");
}
else
{
printf("\nEnter position for deletion : ");
scanf("%d",&p);
if((p<=m) && (p>=1) )
{
if(p==1)
{
head=head->next;
head->prev=NULL;
}
else
{
last=head;
for(i=1;i<p-1;i++)
{
last=last->next;
}
last->next=(last->next)->next;
((last->next)->next)->prev=last;
}
}
else
{
printf("\nSuch position does not exist ");
}
}
}
else if(t==2)
{
while(last->next!=NULL)
{
last=last->next;
}
printf("\nReverse link list is: ");
while(last!=NULL)
{
printf(" %d",last->data);
last=last->prev;
}
}
else
{
printf("\nwrong choice\n");
}
}
}
void main()
{
int ch=0;
clrscr();
while(ch!=5)
{
printf("\n1)create\n2)insert\n3)delet\n4)traverse\n5)Exit\n");
printf("Enter operation to perform: ");
scanf(" %d",&ch);
switch(ch)
{
case 1: create();
break;
case 2: insert();
break;
case 3: delet();
break;
case 4: traverse();
break;
case 5: printf("\n***EXIT***\n");
break;
default: printf("\nEnter proper choice");
}
// printf("\nEnter operation to perform");
// scanf(" %d",&ch);
}
getch();
}