#include <stdio.h>
#include<stdlib.h>
struct node
{
struct node *lpt;
struct node *rpt;
int info;
};
struct node *first;
int main()
{
int s;
void create();
void inbeg();
void inend();
void inloc();
void delbeg();
void delend();
void delgiv();
while(1)
{
printf("\n1. Create");
printf("\n2. Insertion Beginning");
printf("\n3. Insertion at end");
printf("\n4. Insertion at given location");
printf("\n5. Deletion at the beginning");
printf("\n6. Deletion at the end");
printf("\n7. Deletion at given location");
printf("\n8. Exit");
printf("\nEnter Your Choice:");
scanf("%d",&s);
switch(s)
{
case 1: create();
break;
case 2: inbeg();
break;
case 3: inend();
break;
case 4: inloc();
break;
case 5: delbeg();
break;
case 6: delend();
break;
case 7: delgiv();
break;
case 8: exit(0);
default: printf("\nEnter correct value");
}
}
return 0;
}
void create()
{
char ch;
struct node *ptr,*cpt;
ptr=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the node information:");
scanf("%d",&ptr->info);
ptr->lpt=NULL;
first=ptr;
do{
cpt=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the node information:");
scanf("%d",&cpt->info);
ptr->rpt=cpt;
cpt->lpt=ptr;
ptr=cpt;
printf("\nPress 'y' for more nodes");
scanf("%s",&ch);
}
while(ch=='y');
ptr->rpt=NULL;
ptr=first;
while(ptr!=NULL)
{
printf("\t%d",ptr->info);
ptr=ptr->rpt;
}
}
void inbeg()
{
struct node *ptr;
ptr=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the node information:");
scanf("%d",&ptr->info);
ptr->rpt=first;
first->lpt=ptr;
first=ptr;
ptr=first;
while(ptr!=NULL)
{
printf("\t%d",ptr->info);
ptr=ptr->rpt;
}
}
void inend()
{
struct node *ptr,*cpt;
ptr=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the node information:");
scanf("%d",&ptr->info);
cpt=first;
while(cpt->rpt!=NULL)
{
cpt=cpt->rpt;
}
cpt->rpt=ptr;
ptr->lpt=cpt;
ptr->rpt=NULL;
ptr=first;
while(ptr!=NULL)
{
printf("\t%d",ptr->info);
ptr=ptr->rpt;
}
}
void inloc()
{
int loc;
struct node *ptr,*cpt,*tpt;
ptr=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the node information:");
scanf("%d",&ptr->info);
cpt=first;
printf("/n Enter Location:");
scanf("%d",&loc);
while(cpt->info!=loc)
{
cpt=cpt->rpt;
}
tpt=cpt->rpt;
cpt->rpt=ptr;
ptr->lpt=cpt;
ptr->rpt=tpt;
tpt->lpt=ptr;
ptr=first;
while(ptr!=NULL)
{
printf("\t%d",ptr->info);
ptr=ptr->rpt;
}
}
void delbeg()
{
struct node *ptr;
ptr=first;
first=ptr->rpt;
ptr->lpt=NULL;
free(ptr);
ptr=first;
while(ptr!=NULL)
{
printf("\t%d",ptr->info);
ptr=ptr->rpt;
}
}
void delend()
{
struct node *ptr,*cpt;
ptr=first;
while(ptr->rpt!=NULL)
{
cpt=ptr;
ptr=ptr->rpt;
}
cpt->rpt=NULL;
ptr->lpt=NULL;
free(ptr);
ptr=first;
while(ptr!=NULL)
{
printf("\t%d",ptr->info);
ptr=ptr->rpt;
}
}
void delgiv()
{
int loc;
struct node *ptr,*cpt,*tpt;
cpt=first;
printf("\n Enter Location:");
scanf("%d",&loc);
while(cpt->info!=loc)
{
cpt=cpt->rpt;
}
ptr=cpt->lpt;
tpt=cpt->rpt;
ptr->rpt=tpt;
tpt->lpt=ptr;
cpt->lpt=NULL;
cpt->rpt=NULL;
free(cpt);
ptr=first;
while(ptr!=NULL)
{
printf("\t%d",ptr->info);
ptr=ptr->rpt;
}
}