0% found this document useful (0 votes)
10 views3 pages

Data Structure-82-84

Uploaded by

briley.boede
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Data Structure-82-84

Uploaded by

briley.boede
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

} }

if(prev!=NULL)
prev->link=tmp->link;
else
head=tmp->link;
printf("deleted element: %d\n",tmp->data);
free(tmp);
}
void display()
{
pnodeptr=head;
while(ptr!=NULL)
{
printf("%d-->",ptr->data);
ptr=ptr->link;
}
printf("\n");
getch();
}
OUTPUT:
1. Ins beg
2. el beg
3. Ins end
4. Del end
5. Ins after
6. Del mid
7. Display
8. Exit
Enter your choice: 1
Enter element to insert: 94
1. Ins beg
2. Del beg
3. Ins end
4. Del end
5. Ins after
6. Del mid
7. Display
8. Exit
Enter your choice: 1
Enter element to insert: 90
1. Ins beg
2. Del beg
3. Ins end
4. Del ed
5. Ins after
6. Del mid
7. Display
8. Exit

80
Enter your choice 5
Enter element, Pos to insert
55 2

1. Ins beg
2. Del beg
3. Ins end
4. Del end
5. Ins after
6. Del mid
7. Display
8. Exit
Enter your choice 7 90->94->55->
1. Ins beg
2. Del beg
3. Ins end
4. Del end
5. Ins after
6. Del mid
7. Display
8. Exit
Enter your choice 8

6: DOUBLY LINKED LIST


Program:
#include<stdio.h>
#include<conio.h> struct node
{
struct node *prev; int data;
struct node *nxt;
}
*head=NULL,*curr=NULL,*curr1=NULL,*p;

void insert(int pos)


{
int count=1,i; p=head;
while(p->nxt!=NULL)
{
count++; p=p->nxt;
}
p=head;
if(pos<=count+1)
{
curr=(struct node*)malloc(sizeof(struct node));
printf("Enter the node:");
scanf("%d",&curr->data);
curr->nxt=NULL;
curr->prev=NULL;
if(head==NULL)

81
{
head=curr; }
else if(pos==1)
{
head->prev=curr;
curr->nxt=head;
head=curr; }
else
{ for(i=1;i<(pos-1);i++) p=p->nxt;
curr->prev=p; curr->nxt=p->nxt;
p->nxt->prev=curr;
p->nxt=curr;
}
printf("\n%d inserted at pos:%d!\n",curr->data,pos);
}
else
printf("\nEnter a valid position!");

}
void deletenode(int data)
{
int found=0; curr=head; if(head->data == data)
{
(head->nxt)->prev=NULL; head=head->nxt;
printf("\n%d deleted!\n",curr->data);
free(curr);
}
else
{
curr=curr->nxt;
while(curr->nxt!=NULL)
{
if(curr->data==data)
{
found=1;
break;
}
else
curr=curr->nxt;
}
if(found==1 || curr->data==data)
{
curr1=curr->prev; curr1->nxt=curr->nxt; (curr->nxt)->prev=curr1; printf("\n%d
deleted!\n",curr->data); free(curr);
}
else
printf("\n%d is not present in the list!\n",data);
} }
void display()

82

You might also like