-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwoStackQueue.java
35 lines (31 loc) · 956 Bytes
/
twoStackQueue.java
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
/* *****************************************************************************
* Name: Alan Turing
* NetID: aturing
* Precept: P00
*
* Description: Prints 'Hello, World' to the terminal window.
* By tradition, this is everyone's first program.
* Prof. Brian Kernighan initiated this tradition in 1974.
*
**************************************************************************** */
import edu.princeton.cs.algs4.Stack;
public class twoStackQueue<Item> {
private Stack<Item> in = new Stack<Item>();
private Stack<Item> out = new Stack<Item>();
public void enqueue(Item item){
in.push(item);
}
public Item dequeue(){
if(out.isEmpty())
{
while(!in.isEmpty())
{
Item i = in.pop();
out.push(i);
}
}
return out.pop();
}
public static void main(String[] args) {
}
}