-
Notifications
You must be signed in to change notification settings - Fork 3
/
622.cpp
49 lines (42 loc) · 993 Bytes
/
622.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
class MyCircularQueue {
public:
list<int> l;
int k;
MyCircularQueue(int k) {
this->k = k;
}
bool enQueue(int value) {
if (l.size() == k) return false;
l.push_back(value);
return true;
}
bool deQueue() {
if (l.size() == 0) return false;
l.pop_front();
return true;
}
int Front() {
if (l.empty()) return -1;
return l.front();
}
int Rear() {
if (l.empty()) return -1;
return l.back();
}
bool isEmpty() {
return l.empty();
}
bool isFull() {
return l.size() == k;
}
};
/**
* Your MyCircularQueue object will be instantiated and called as such:
* MyCircularQueue* obj = new MyCircularQueue(k);
* bool param_1 = obj->enQueue(value);
* bool param_2 = obj->deQueue();
* int param_3 = obj->Front();
* int param_4 = obj->Rear();
* bool param_5 = obj->isEmpty();
* bool param_6 = obj->isFull();
*/