AcWing 826. 单链表(C)
原题链接
简单
作者:
coquetish
,
2024-12-02 13:54:52
,
所有人可见
,
阅读 7
#include <stdio.h>
struct Node{
int value;
Node *next;
}a[100001], *head;
int idx;
int main() {
int m;
scanf("%d", &m);
head = NULL;
for(; m --; ) {
char op;
scanf(" %c", &op);
if(op == 'H') {
int x;
scanf("%d", &x);
a[++idx].value = x;
a[idx].next = head;
head = &a[idx];
}else if(op == 'D') {
int k;
scanf("%d", &k);
if(!k) {
head = head->next;
} else {
a[k].next = a[k].next->next;
}
} else {
int k, x;
scanf("%d%d", &k, &x);
a[++idx].value = x;
a[idx].next = a[k].next;
a[k].next = &a[idx];
}
}
for(Node *p = head; p; p = p->next) {
printf("%d ", p->value);
}
}