-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path641.cpp
82 lines (70 loc) · 1.41 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class MyCircularDeque
{
public:
vector<int> v;
int size1;
/** Initialize your data structure here. Set the size of the deque to be k. */
MyCircularDeque(int k)
{
size1 = k;
}
/** Adds an item at the front of Deque. Return true if the operation is successful. */
bool insertFront(int value)
{
if (v.size() >= size1)
return false;
v.insert(v.begin(), value);
return true;
}
/** Adds an item at the rear of Deque. Return true if the operation is successful. */
bool insertLast(int value)
{
if (isFull())
return false;
v.push_back(value);
return true;
}
/** Deletes an item from the front of Deque. Return true if the operation is successful. */
bool deleteFront()
{
if (isEmpty())
return false;
v.erase(v.begin());
return true;
}
/** Deletes an item from the rear of Deque. Return true if the operation is successful. */
bool deleteLast()
{
if (v.empty())
return false;
v.pop_back();
return true;
}
/** Get the front item from the deque. */
int getFront()
{
if (v.empty())
return -1;
return v[0];
}
/** Get the last item from the deque. */
int getRear()
{
if (isEmpty())
return -1;
return v[v.size() - 1];
}
/** Checks whether the circular deque is empty or not. */
bool isEmpty()
{
return v.empty();
}
/** Checks whether the circular deque is full or not. */
bool isFull()
{
if (v.size() >= size1)
return true;
else
return false;
}
};