-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution9.java
More file actions
35 lines (29 loc) · 772 Bytes
/
Solution9.java
File metadata and controls
35 lines (29 loc) · 772 Bytes
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
class CQueue {
Stack mStack1;
Stack mStack2;
public CQueue() {
mStack1 = new Stack();
mStack2 = new Stack();
}
public void appendTail(int value) {
mStack1.push(value);
}
public int deleteHead() {
if (mStack2.isEmpty()) {
if (mStack1.isEmpty()) {
return -1;
} else {
while (!mStack1.isEmpty()) {
mStack2.push(mStack1.pop());
}
return (int) mStack2.pop();
}
} else {
return (int) mStack2.pop();
}
}
}
/**
* Your CQueue object will be instantiated and called as such: CQueue obj = new
* CQueue(); obj.appendTail(value); int param_2 = obj.deleteHead();
*/