模拟队列
题目 模拟队列
思路分析
同理 熟悉api
代码实现
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
Queue<Integer> q = new LinkedList<>();
while(n-- > 0){
String op=sc.next();
if(op.equals("push")){
int x=sc.nextInt();
q.add(x);
}else if(op.equals("pop")){
q.remove();
}else if(op.equals("empty")){
if(q.isEmpty()) System.out.println("YES");
else System.out.println("NO");
}else{
System.out.println(q.peek());
}
}
}
}
💬 评论