mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 18:28:47 +00:00
827. 双链表
https://www.acwing.com/problem/content/submission/code_detail/7412150/
This commit is contained in:
parent
2ea750984c
commit
01ab18dd50
39
AcWing/827/827.cpp
Normal file
39
AcWing/827/827.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int m, x, k, p;
|
||||
string op;
|
||||
list<int> a;
|
||||
list<int>::iterator it[100005];
|
||||
|
||||
int main() {
|
||||
cin >> m;
|
||||
while (m--) {
|
||||
cin >> op;
|
||||
if (op == "L") {
|
||||
cin >> x;
|
||||
a.push_front(x);
|
||||
it[++p] = a.begin();
|
||||
} else if (op == "R") {
|
||||
cin >> x;
|
||||
a.push_back(x);
|
||||
it[++p] = --a.end();
|
||||
} else if (op == "D") {
|
||||
cin >> k;
|
||||
a.erase(it[k]);
|
||||
} else if (op == "IL") {
|
||||
cin >> k >> x;
|
||||
it[++p] = a.insert(it[k], x);
|
||||
} else {
|
||||
cin >> k >> x;
|
||||
auto itk = it[k];
|
||||
it[++p] = a.insert(++itk, x);
|
||||
}
|
||||
}
|
||||
for (int i : a) {
|
||||
cout << i << ' ';
|
||||
}
|
||||
cout << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user