-
Notifications
You must be signed in to change notification settings - Fork 3
/
641.cpp
63 lines (54 loc) · 1.32 KB
/
641.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
class MyCircularDeque {
public:
list<int> l;
int k;
MyCircularDeque(int k) {
this->k = k;
}
bool insertFront(int value) {
if (l.size() == k) return false;
l.push_front(value);
return true;
}
bool insertLast(int value) {
if (l.size() == k) return false;
l.push_back(value);
return true;
}
bool deleteFront() {
if (l.size() == 0) return false;
l.pop_front();
return true;
}
bool deleteLast() {
if (l.size() == 0) return false;
l.pop_back();
return true;
}
int getFront() {
if (l.empty()) return -1;
return l.front();
}
int getRear() {
if (l.empty()) return -1;
return l.back();
}
bool isEmpty() {
return l.empty();
}
bool isFull() {
return l.size() == k;
}
};
/**
* Your MyCircularDeque object will be instantiated and called as such:
* MyCircularDeque* obj = new MyCircularDeque(k);
* bool param_1 = obj->insertFront(value);
* bool param_2 = obj->insertLast(value);
* bool param_3 = obj->deleteFront();
* bool param_4 = obj->deleteLast();
* int param_5 = obj->getFront();
* int param_6 = obj->getRear();
* bool param_7 = obj->isEmpty();
* bool param_8 = obj->isFull();
*/