import java.util.Scanner;
public class Main {
public static int N = 100010;
public static int head;//头位置
public static int[] e = new int[N];//值
public static int[] ne = new int[N];//下个结点位置
public static int idx;//点用到哪里
static {
head = -1; // 没有头结点
idx = 0; // 没有存入数据
}
public static void add_to_head(int x) {
e[idx] = x;
ne[idx] = head;
head = idx;
idx++;
}
public static void add(int k, int x) {
e[idx] = x;
ne[idx] = ne[k];
ne[k] = idx;
idx++;
}
public static void remove(int k) {
ne[k] = ne[ne[k]];
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
while (m-- != 0) {
String op = sc.next();
int k, x;
if (op.equals("H")) {
x = sc.nextInt();
add_to_head(x);
} else if (op.equals("D")) {
k = sc.nextInt();
if (k == 0) {
head = ne[head];
}else
remove(k - 1);
} else {
k = sc.nextInt();
x = sc.nextInt();
add(k - 1, x);
}
}
for (int i = head; i != -1; i = ne[i]) {
System.out.print(e[i]+" ");
}
System.out.println();
}
}
暑期编程PK赛
得CSDN机械键盘等精美礼品!