AcWing 826. 静态数组链表
原题链接
简单
作者:
RiCharZh
,
2021-03-09 10:30:51
,
所有人可见
,
阅读 305
#include <iostream>
using namespace std;
char c;
int idx = 0, head = -1;
const int N = 100010;
int ne[N], e[N];
void add_h(int x)
{
e[idx] = x;
ne[idx] = head;
head = idx++;
}
void add_k(int k, int x)
{
e[idx] = x;
ne[idx] = ne[k];
ne[k] = idx++;
}
void dele(int k)
{
ne[k] = ne[ne[k]];
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> c;
int k, x;
switch(c)
{
case 'H' :
{
cin >> x;
add_h(x);
break;
}
case 'I' :
{
cin >> k >> x;
add_k(k - 1, x);
break;
}
case 'D' :
{
cin >> k;
if (!k) head = ne[head];
else dele(k - 1);
break;
}
}
}
for (int i = head; i != -1; i = ne[i])
cout << e[i] << ' ';
return 0;
}