forked from gods-mack/Workspace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdblylist.cpp
More file actions
134 lines (104 loc) · 1.68 KB
/
dblylist.cpp
File metadata and controls
134 lines (104 loc) · 1.68 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include<iostream>
using namespace std;
struct node
{
int data;
node *prv;
node *next;
};
class list
{
node *t,*h;
public:
list() { t=NULL; h=NULL; }
void add(int x)
{
node *n=new node;
n->data=x;
if(h==NULL)
{ t=h=n; }
else
{
n->next=NULL;
n->prv=t;
t->next=n;
t=n;
}
}
void add_front(int x)
{
node *n=new node;
n->prv=NULL;
n->data=x;
h->prv=n;
n->next=h;
h=n;
}
void add_after(int after,int item)
{ node *tmp;
tmp=h;
//node *n= new node;
while(tmp!=NULL)
{
if(tmp->data==after)
break;
tmp=tmp->next; }
if(tmp==NULL)
{ cout<<"item not present"<<endl; }
else
{ node *n= new node;
n->data=item;
n->prv=tmp;
// cout<<tmp->data<<" "<<endl;
n->next=tmp->next ;
(tmp->next)->prv=n;
// cout<<(tmp->next)->data<<" "<<endl;
tmp->next=n;
// cout<<(tmp->next)->data<<" "<<endl;
}
}
void reverse()
{
node *tmp;
tmp=t;
while(tmp!=NULL)
{
cout<<tmp->data<<" ";
tmp=tmp->prv;
}
}
void del_front()
{
node *tmp;
tmp=h; h=h->next;
(tmp->next)->prv=NULL;
h=tmp->next; delete tmp;
}
void print()
{
node *tmp;
tmp=h;
while(tmp!=NULL)
{
cout<<tmp->data<<" ";
tmp=tmp->next;
}
}
};
int main()
{
list a;
a.add(33);
a.add(24);
a.add(100);
a.add_front(1000);
a.add_front(1001);
a.add_front(1002);
a.add(999);
//a.add_after(1002,99899);
//a.add_after(100,100238);
a.add_after(33,111111);
a.del_front();
a.print(); cout<<endl;
a.reverse();
}