Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

#include<stdio.

h>

#include<conio.h>

struct node

int data;

struct node *next;

struct node *prev;

};

struct node *head;

void create();

void display();

void insert();

void del(int);

int isempty();

void create()

int x,i,n;

struct node *temp,*temp1;

printf("\nEnter the no of elements:");

scanf("%d",&n);

temp=(struct node*) malloc(sizeof(struct node));

printf("\nEnter the data:");

scanf("%d",&x);

temp->data=x;

temp->next=NULL;

temp->prev=NULL;

1
head=temp;

for(i=1;i<n;i++)

printf("\nEnter the data:");

scanf("%d",&x);

temp1=(struct node*) malloc(sizeof(struct node));

temp1->data=x;

temp1->next=NULL;

temp1->prev=temp;

temp->next=temp1;

temp=temp1;

display();

void display()

struct node *temp;

temp=head;

if(head==NULL)

{printf("LIST is EMPTY");

else

while(temp->next!=NULL)

printf("%d<===>",temp->data);

2
temp=temp->next;

printf("%d",temp->data);

void insert()

int ch,x,y;

struct node *temp,*temp1;

printf("\nEnter the number:");

scanf("%d",&x);

printf("\choose where to insert:\n1.first\n2.middle\n3.last\n0.exit:");

scanf("%d",&ch);

switch(ch)

case 1:

temp=(struct node*) malloc(sizeof(struct node));

temp->data=x;

temp->next=head;

temp->prev=NULL;

head->prev=temp;

head=temp;

display();

break;

case 2:

printf("\nEnter the element you want to insert after:");

3
scanf("%d",&y);

temp=head;

while(temp->data!=y)

temp=temp->next;

temp1=(struct node*) malloc(sizeof(struct node));

temp1->data=x;

temp1->next=temp->next;

temp1->prev=temp;

temp->next->prev=temp1;

temp->next=temp1;

display();

break;

case 3:

temp=head;

while(temp->next!=NULL)

temp=temp->next;

temp1=(struct node*) malloc(sizeof(struct node));

temp1->data=x;

temp1->next=NULL;

temp1->prev=temp;

temp->next=temp1;

display();

4
break;

default:

printf("\nCheck the value:");

void del(int x)

struct node *temp,*temp1;

temp=head;

if(head->data==x)

{ head=head->next;

head->prev=NULL;

free(temp);

else

{ while(temp->data!=x &&temp->next!=NULL)

{ temp1=temp;

temp=temp->next;

if( temp->data==x)

{temp1->next=temp->next;

temp->next->prev=temp1;

printf("\nthe deleted data is %d\n",temp->data);

free(temp);

5
}

else{ printf("data is not in the list");

display();

int isempty()

if(head==NULL)

return 1;

else

return 0;

void main()

int ch,a;

clrscr();

create();

do

printf("\nEnter your choice:\n1.Insert\n2.Delete:");

scanf("%d",&ch);

switch(ch)

case 1:

insert();

6
break;

case 2:

if(!isempty())

printf("\nEnter the element to be deleted :");

scanf("%d",&a);

del(a);

else

printf("\nLIST is EMPTY");

break;

default:

printf("\check the value:");

}while(ch!=0);

getch();

You might also like