MyQueue

 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
import java.util.HashMap;
import java.util.LinkedList;
public class MyQueue {
private static LinkedList<String> queue1 = new LinkedList<String>();
private static LinkedList<String> queue2 = new LinkedList<String>();
public static void put(String value) {
if (value.length() == 1) {
queue1.add(value);
} else {
queue2.add(value);
}
}
public static String get() {
if (!queue2.isEmpty()) {
return queue2.removeFirst();
} else if (!queue1.isEmpty()) {
return queue1.removeFirst();
} else {
return "queue is empty";
}
}
}