-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.DOUBLY_DELETE.cpp
100 lines (97 loc) · 1.39 KB
/
1.DOUBLY_DELETE.cpp
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
94
95
96
97
98
99
100
#include<iostream>
using namespace std;
class binnum
{
int no;
binnum*next;
binnum*back;
public:
friend class list;
};
class list
{
binnum*root;
binnum*curr;
binnum*prev;
public:
list()
{
root=NULL;
curr=NULL;
prev=NULL;
}
void create()
{
while(1)
{
curr = new binnum;
cout<<"Enter no : ";
cin>>curr->no;
if(curr->no == 0)
break;
curr->next=NULL;
curr->back=NULL;
if(root == NULL)
{
root=curr;
prev=curr;
}
else
{
prev->next=curr;
curr->back=prev;
prev=curr;
}
}
}
void display()
{
cout<<"\n";
curr=root;
while(curr!=NULL)
{
cout<<curr->no<<" ";
curr=curr->next;
}
}
void delete_no()
{
binnum*temp;
temp=NULL;
int del;
cout<<"\nEnter no u want to delete : ";
cin>>del;
curr=root;
while(curr!=NULL)
{
if(curr->no == del)
{
if(curr==root)
{
root=root->next;
curr=root;
return;
}
prev->next=curr->next;
temp=curr->next;
delete curr;
curr=temp;
curr->back=prev;
//dont increment current to next ie curr=curr->next
}
else
{
prev=curr;
curr=curr->next;
}
}
}
};
main()
{
list l;
l.create();
l.display();
l.delete_no();
l.display();
}