--- title: "04-模拟队列" created: 2025-12-02 tags: - 项目 aliases: - 模拟队列 --- # 模拟队列 ## 题目 [模拟队列](https://www.acwing.com/problem/content/831/) ![[image-8414d767.png]] ## 思路分析 同理 熟悉api ## 代码实现 ```java import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); Queue 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()); } } } } ``` ## 同类题型 ## 视频讲解 --- **项目分区导航**: [[03-模拟栈|模拟栈]] ⬅️ | 04-模拟队列 | ➡️ [[05-邻值查找|邻值查找]]