forked from AllAlgorithms/cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoubly_Linked_List.cpp
More file actions
93 lines (75 loc) · 1.25 KB
/
Copy pathDoubly_Linked_List.cpp
File metadata and controls
93 lines (75 loc) · 1.25 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
struct node{
int info;
node *left,*right;
}*ptr,*start,*last,*save;
int c=1,i=0,data,item;
start=last=NULL;
while(c<4 && c>0){
cout<<"1.Insert\n2.Deletion\n3.Link List\n";
cin>>c;
switch(c){
case 1:
cout<<"Enter Data\n";
cin>>data;
ptr=new node;
ptr->info=data;
ptr->left=last;
ptr->right=NULL;
if(start==NULL){
start=last=ptr;
}
else{
last->right=ptr;
last=ptr;
}
break;
case 2:
if(start==NULL){
cout<<"Underflow\n";
}
else{
cout<<"Enter Item to be Deleted\n";
cin>>item;
ptr=start;
while(ptr!=NULL){
if(ptr->info==item){
i++;
if(ptr==start){
start->left=NULL;
start=start->right;
}
else{
ptr->left->right=ptr->right;
ptr->right->left=ptr->left;
}
delete ptr;
cout<<"Item Deleted\n";
}
ptr=ptr->right;
}
if(i==0){
cout<<"Item Does not exist\n";
}
i=0;
}
break;
case 3:
ptr=start;
while(ptr!=NULL){
cout<<ptr->info<<"->";
ptr=ptr->right;
}
cout<<"\n";
break;
default:
cout<<"Wrong Choice\nExiting...\n";
}
}
getch();
return 0;
}