-
Notifications
You must be signed in to change notification settings - Fork 265
Expand file tree
/
Copy path6.java
More file actions
32 lines (30 loc) · 675 Bytes
/
6.java
File metadata and controls
32 lines (30 loc) · 675 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
class CQueue {
private Stack<Integer> a;
private Stack<Integer> b;
public CQueue() {
a=new Stack<Integer>();
b=new Stack<Integer>();
}
public void appendTail(int value) {
a.push(value);
}
public int deleteHead() {
if(!b.empty()){
return b.pop();
}
else if(a.empty()){
return -1;
}
else{
while(!a.empty())
b.push(a.pop());
return b.pop();
}
}
}
/**
* Your CQueue object will be instantiated and called as such:
* CQueue obj = new CQueue();
* obj.appendTail(value);
* int param_2 = obj.deleteHead();
*/