单链表模板
作者:
呆比小昱
,
2021-11-20 21:07:06
,
所有人可见
,
阅读 218
单链表模板
#include <iostream>
using namespace std;
const int N = 100010;
int head, e[N], ne[N], idx;
void init()
{
head = -1;
idx = 0;
}
void add_to_head(int x)
{
e[idx] = x;
ne[idx] = head;
head = idx ++;
}
void add(int k, int x)
{
e[idx] = x;
ne[idx] = ne[k];
ne[k] = idx ++;
}
void remove(int k)
{
ne[k] = ne[ne[k]];
}
int main()
{
init();
int m;
scanf("%d", &m);
while (m -- )
{
int k, x;
char op;
cin >> op;
if (op == 'H')
{
scanf("%d", &x);
add_to_head(x);
}
else if (op == 'D')
{
scanf("%d", &k);
if(!k) head = ne[head];
else remove(k - 1);
}
else
{
scanf("%d%d", &k, &x);
add(k - 1, x);
}
}
for (int i = head; i != -1; i = ne[i]) printf("%d ", e[i]);
return 0;
}
干完就睡觉!!!
姐姐巨!QWQ