-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimuQueue.java
More file actions
27 lines (27 loc) · 825 Bytes
/
SimuQueue.java
File metadata and controls
27 lines (27 loc) · 825 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
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class SimuQueue {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int M = sc.nextInt();
Queue<Integer> que = new LinkedList<>();
while (M -- > 0){
String op = sc.next();
if (op.equals("push")){
int x = sc.nextInt();
que.add(x);
} else if (op.equals("pop")) {
que.remove();
} else if (op.equals("empty")) {
if (que.isEmpty()){
System.out.println("YES");
}else {
System.out.println("NO");
}
} else {
System.out.println(que.peek());
}
}
}
}