-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDLL.cpp
111 lines (83 loc) · 1.34 KB
/
DLL.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
101
102
103
104
105
106
107
108
109
110
#include<iostream>
using namespace std;
class DLL
{
private: struct node
{
struct node *prev;
int data;
struct node *next;
}*start,*end;
public:
DLL()
{
start = NULL;
end = NULL;
}
void insert()
{
struct node *temp;
temp = (struct node *)malloc(sizeof(struct node));
if(temp == NULL)
{
cout<<"\nMemory allocation failed";
return;
}
cout<<"\nEnter data:";
cin>>temp->data;
temp->prev = NULL;
temp->next = NULL;
if(start == NULL)
{
start = temp;
end = temp;
}
else
{
struct node *t = start;
while(t->next !=NULL)
{
t = t->next;
}
t->next = temp;
temp->prev = t;
end = temp;
}
}
void disp()
{
struct node *t = start;
if(t == NULL)
{
cout<<"\nList is MT";
return;
}
while(t != NULL)
{
cout<<endl<<t->data;
t = t->next;
}
cout<<"\nStart - "<<start->data<<" End - "<<end->data<<endl;
}
void del() //delete last node
{
struct node *l,*sl;
l = end;
sl = l->prev;
l->prev = NULL;
sl->next = NULL;
end = sl;
free(l);
}
};
int main()
{
DLL l;
l.insert();
l.insert();
l.insert();
l.disp();
l.del();
l.disp();
return 0;
}