-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9.cpp
42 lines (38 loc) · 786 Bytes
/
9.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
class CQueue
{
private:
stack<int> main_stk, assist_stk;
public:
CQueue()
{
return;
}
void appendTail(int value)
{
main_stk.push(value);
}
int deleteHead()
{
if (main_stk.empty())
return -1;
while (!main_stk.empty())
{
assist_stk.push(main_stk.top());
main_stk.pop();
};
int ans = assist_stk.top();
assist_stk.pop();
while (!assist_stk.empty())
{
main_stk.push(assist_stk.top());
assist_stk.pop();
};
return ans;
}
};
/**
* Your CQueue object will be instantiated and called as such:
* CQueue* obj = new CQueue();
* obj->appendTail(value);
* int param_2 = obj->deleteHead();
*/