#include
#include
void delete_specific();
void delete_end();
void delete_beg();
void allocate();
void create();
void insert_beg();
void insert_specific();
void insert_end();
void list();
void menu();
struct node
{
struct node *pre;
int info;
struct node *next;
};
typedef struct node ND;
ND *refresh,*start=0,*temp,*pv=0,*tt;
main()
{
char ch='1';
clrscr();
create();
while(1)
{
menu();
if(ch=='2'||ch=='3'||ch=='4')
allocate();
if(ch=='1')
list();
if(ch=='2')
insert_beg();
if(ch=='3')
insert_end();
if(ch=='4')
insert_specific();
if(ch=='5')
delete_beg();
if(ch=='6')
delete_end();
if(ch=='7')
delete_specific();
if(ch=='8')
exit(1);
ch=getche();
}
}
void allocate()
{
refresh=(ND*)malloc(sizeof(ND));
printf("\nenter the data-> ");
scanf("%d",&refresh->info);
refresh->pre=pv;
refresh->next=0;
}
void create()
{
char ch;
do
{
allocate();
if(start==0)
{
start=refresh;
pv=refresh;
}
else
{
pv->next=refresh;
pv=refresh;
}
printf("\tdo you want to continue(y/n)-> "); fflush(stdin);
ch=getch();
} while(ch!='n'&&ch!='N');
}
void list()
{
temp=start;
printf("\n\nTraversing the List \n\n");
while(temp!=0)
{
printf("\n\t\t%d",temp->info);
temp=temp->next;
}
if(start==0)
pv=0;
temp=pv;
printf("\n\nTraversing the List in reverse order\n\n");
while(temp!=0)
{
printf("\n\t\t%d",temp->info);
temp=temp->pre;
}
}
void menu()
{
clrscr();
gotoxy(35,1); printf("MENU");
gotoxy(10,2);printf("----------------------------------------------");
gotoxy(32,4); printf("1. List data");
gotoxy(32,5); printf("2. Insert at Biginning");
gotoxy(32,6); printf("3. Insert at the End");
gotoxy(32,7); printf("4. Insert at the the specified position");
gotoxy(32,8); printf("5. Delete at Beginning");
gotoxy(32,9); printf("6. Delete at End");
gotoxy(32,10); printf("7. Delete at Specific Position");
gotoxy(32,11); printf("8. EXIT");
gotoxy(10,12);printf("----------------------------------------------");
printf("\nenter your choice-> ");
}
void insert_beg()
{
start->pre=refresh;
refresh->next=start;
refresh->pre=0;
start=refresh;
}
void insert_end()
{
pv->next=refresh;
refresh->pre=pv;
pv=refresh;
}
void insert_specific()
{
int a=1,pos;
printf("enter the position->");
scanf("%d",&pos);
if(pos==1)
{
insert_beg();
return;
}
temp=start;
for(;a
if(temp->next==0)
{
printf("data in the list are less");
return;
}
refresh->next=temp->next;
(temp->next)->pre=refresh;
refresh->pre=temp;
temp->next=refresh;
}
void delete_beg()
{
temp=start;
start=start->next;
start->pre=0;
free(temp);
}
void delete_end()
{
temp=pv;
pv=pv->pre;
pv->next=0;
free(temp);
}
void delete_specific()
{
int pos,a=1;
printf("enter position ->");
scanf("%d",&pos);
temp=start;
if(pos==1)
{ delete_beg();
return;
}
for(;a
if(temp->next==0)
{
printf("data are lessthan the number you have entered");
return;
}
tt=temp->next;
if(tt->next==0)
pv=tt->pre;
temp->next=tt->next;
(tt->next)->pre=temp;
free(tt);
}
0 comments:
Post a Comment