AcWing 827 双链表
个人记录自用,未加注释
/*
AcwWing 827. 双链表
2021年7月23日15:57:44
By ZenFish
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5+10;
int main() {
int e[N],idx = 2;
pair<int,int> ne[N];
ne[0] = {0,1},ne[1] = {0,1};
int M; cin >> M;
while(M--) {
string c; cin >> c;
if(c == "L") {
cin >> e[idx];
ne[ne[0].second].first = idx;
ne[idx].second = ne[0].second;
ne[0].second = idx,ne[idx].first = 0;
idx ++;
} else if (c == "R") {
cin >> e[idx];
ne[idx].first = ne[1].first;
ne[ne[1].first].second = idx;
ne[1].first = idx,ne[idx].second = 1;
idx ++;
} else if(c == "D") {
int k; cin >> k;
ne[ne[k+1].first].second = ne[k+1].second;
ne[ne[k+1].second].first = ne[k+1].first;
} else if(c == "IL") {
int k; cin >> k >> e[idx];
ne[idx].first = ne[k+1].first;
ne[ne[k+1].first].second = idx;
ne[k+1].first = idx,ne[idx].second = k+1;
idx ++;
} else if(c == "IR") {
int k; cin >> k >> e[idx];
ne[ne[k+1].second].first = idx;
ne[idx].second = ne[k+1].second;
ne[k+1].second = idx,ne[idx].first = k+1;
idx ++;
}
}
for(int i = ne[0].second;i != 1;i = ne[i].second) {
cout << e[i] << ' ';
} cout << endl;
//cout << ne[0].second;
return 0;
}