题目描述
blablabla
样例
blablabla
算法1
Java 代码
import java.io.*;
public class Main {
private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
private static final int maxSize = 100010; // 数组最大容量
private static int front = -1; // 队列头
private static int rear = -1; // 队列尾
static int[] q = new int[maxSize]; // 数据规模为 10w
// 入队
public static void push(int val) {
if(isFull()) return;
q[++rear] = val;
}
// 出队
public static int pop() {
return q[++front];
}
// 判断队列是否为空
public static boolean empty() {
return front == rear;
}
public static boolean isFull() {
return rear == maxSize-1;
}
// 查询队头元素
public static int query() {
return q[front+1];
}
// 查询队尾元素
public static int queryToTail() {
return q[rear];
}
// 程序入口
public static void main(String[] args) throws IOException {
int m = Integer.parseInt(reader.readLine());
while (m-- > 0) {
String[] s = reader.readLine().split(" ");
if (s[0].equals("push")) {
push(Integer.parseInt(s[1]));
} else if (s[0].equals("pop")) {
pop();
} else if (s[0].equals("query")) {
System.out.println(query());
} else { // s[0].equals("empty")
if (empty()) System.out.println("YES");
else System.out.println("NO");
}
}
}
}