-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17.cpp
More file actions
106 lines (96 loc) · 1.98 KB
/
17.cpp
File metadata and controls
106 lines (96 loc) · 1.98 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
#include <iostream>
using namespace std;
struct node {
int x;
node* next;
node* prev;
};
struct dequeue {
node* tail=NULL;
node* head=NULL;
~dequeue() {
while (tail!=NULL) {
node* temp=tail;
tail=tail->next;
delete temp;
}
}
void push_back(int x) {
node* temp = new node;
temp->x=x;
temp->next=tail;
temp->prev=NULL;
tail=temp;
if (head==NULL) {
head=tail;
}
if (tail->next!=NULL) {
tail->next->prev=tail;
}
}
void push_front(int x) {
node* temp=new node;
temp->x=x;
temp->next=NULL;
temp->prev=head;
head=temp;
if (tail==NULL) {
tail=head;
}
if (head->prev!=NULL) {
head->prev->next=head;
}
}
int back() {
if (tail==NULL) {
cout <<"Empty";
return 0;
}
return tail->x;
}
int front() {
if (head==NULL) {
cout <<"empty";
return 0;
}
return head->x;
}
int pop_back() {
if (tail==NULL) {
cout <<"empty";
return 0;
}
int x=tail->x;
if (tail->next!=NULL) {
tail=tail->next;
delete tail->prev;
tail->prev=NULL;
}
else {
delete tail;
tail=head=NULL;
}
return x;
}
int pop_front() {
if (head==NULL) {
cout <<"empty";
return 0;
}
int x=head->x;
if (head->prev!=NULL) {
head=head->prev;
delete head->next;
head->next=NULL;
}
else {
delete head;
head=tail=NULL;
}
return x;
}
};
int main()
{
return 0;
}