-
Notifications
You must be signed in to change notification settings - Fork 282
Expand file tree
/
Copy pathDeletion_inbetween_DoublyLinkedList.cpp
More file actions
56 lines (55 loc) · 1 KB
/
Deletion_inbetween_DoublyLinkedList.cpp
File metadata and controls
56 lines (55 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//DELETION OF DLL ELEMENT IN BETWEEN
//Enter the data as input to delete the DLL
#include <iostream>
using namespace std;
struct node{
int data;
node *ptr,*pre;
};
node *head=NULL;
void insertathead(int a){
node *p=new node;
p->data=a;
p->pre=p->ptr=NULL;
if(head==NULL){
head=p;
}
else{
head->pre=p;
p->ptr=head;
head=p;
}
}
void deleteinbetween(int a){
node *p=head;
while(p && p->data!=a){
p=p->ptr;
}
if(p->ptr==NULL)
cout<<"NOT FOUND";
else{
p->pre->ptr=p->ptr;
p->ptr->pre=p->pre;
}
p=NULL;
}
void displayfromhead(){
node *p=head;
while(p!=NULL){
cout<<p->data<<endl;
p=p->ptr;
}
}
int main(){
insertathead(40);
insertathead(30);
insertathead(20);
insertathead(10);
insertathead(5);
cout<<"BEFORE DELETION\n";
displayfromhead();
deleteinbetween(30);
cout<<"AFTER DELETION in between\n";
displayfromhead();
return 0;
}