We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 87aff18 commit c27d2e3Copy full SHA for c27d2e3
Algorithms 4/Part Ⅰ/week 2/hw2/TwoStackQueue.java
@@ -0,0 +1,27 @@
1
+package com.algs4.hw2;
2
+
3
+import java.util.Stack;
4
5
+public class TwoStackQueue<E>
6
+{
7
+ // interview questions
8
+ private Stack<E> inbox = new Stack<E>();
9
+ private Stack<E> outbox = new Stack<E>();
10
11
+ public void queue(E item)
12
+ {
13
+ inbox.push(item);
14
+ }
15
16
+ public E dequeue()
17
18
+ if (outbox.isEmpty())
19
20
+ while (!inbox.isEmpty())
21
22
+ outbox.push(inbox.pop());
23
24
25
+ return outbox.pop();
26
27
+}
0 commit comments