直接给出代码
#include <iostream>
using namespace std;
const int N = 100005;
int head=-1, idx, e[N], ne[N];
void insertHead(int x) {
e[idx]=x, ne[idx]=head, head=idx++;
}
void insertK(int x, int k) {
e[idx]=x, ne[idx]=ne[k], ne[k]=idx++;
}
void delK(int k) {
ne[k]=ne[ne[k]];
}
int main() {
char c;
int m, oper_one, oper_two;
cin >> m;
while (m--) {
cin >> c;
if (c == 'H') {
cin >> oper_one;
insertHead(oper_one);
}
else if (c == 'D') {
cin >> oper_two;
if (!oper_two) head=ne[head];
delK(oper_two-1);
}
else if (c == 'I') {
cin >> oper_two >> oper_one;
insertK(oper_one, oper_two-1);
}
}
for (int index=head; index!=-1; index=ne[index]) cout << e[index] << " ";
return 0;
}