mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 18:28:47 +00:00
826. 单链表
https://www.acwing.com/problem/content/submission/code_detail/7357618/
This commit is contained in:
parent
8f84512bb8
commit
8dda40185b
37
AcWing/826/826.cpp
Normal file
37
AcWing/826/826.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int m, k, x, t;
|
||||
char op;
|
||||
list<int> a;
|
||||
list<int>::iterator it[100005];
|
||||
|
||||
int main() {
|
||||
cin >> m;
|
||||
while (m--) {
|
||||
cin >> op;
|
||||
if (op == 'H') {
|
||||
cin >> x;
|
||||
a.push_front(x);
|
||||
it[++t] = a.begin();
|
||||
} else if (op == 'D') {
|
||||
cin >> k;
|
||||
if (k == 0) {
|
||||
a.pop_front();
|
||||
} else {
|
||||
auto itk = it[k];
|
||||
a.erase(++itk);
|
||||
}
|
||||
} else {
|
||||
cin >> k >> x;
|
||||
auto itk = it[k];
|
||||
it[++t] = a.insert(++itk, x);
|
||||
}
|
||||
}
|
||||
for (int i : a) {
|
||||
cout << i << ' ';
|
||||
}
|
||||
cout << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user