模板
普通队列
int q[N], hh = 0, tt = 0;
q[tt ++ ] = x;
if (tt == N) tt = 0;
hh ++ ;
if (hh == N) hh = 0;
q[hh];
if (hh != tt)
{
}
循环队列
int q[N], hh = 0, tt = 0;
q[tt ++ ] = x;
if (tt == N) tt = 0;
hh ++ ;
if (hh == N) hh = 0;
q[hh];
if (hh != tt)
{
}
练习
01 模拟队列

import java.io.*;
public class Main {
public static final int N = 100010;
public static int[] q = new int[N];
public static int hh = 0, tt = -1;
public static int M;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
M = Integer.parseInt(br.readLine());
while (M-- > 0) {
String[] str1 = br.readLine().split(" ");
if (str1[0].equals("push")) {
q[++tt] = Integer.parseInt(str1[1]);
} else if (str1[0].equals("pop")) {
hh++;
} else if (str1[0].equals("empty")) {
if (hh <= tt) {
pw.println("NO");
} else {
pw.println("YES");
}
} else {
pw.println(q[hh]);
}
}
pw.close();
br.close();
}
}