826. 单链表
题目链接https://www.acwing.com/problem/content/828/
题目:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=1e5+10;
int head=-1,e[N],ne[N],idx=1;
void insertt(int u,int x){
e[idx]=x;
if(!u){
ne[idx]=head;
head=idx++;
return ;
}
ne[idx]=ne[u];
ne[u]=idx++;
}
void deletee(int x){
if(!x){
if(head!=-1){
head=ne[head];
}
return;
}
if(ne[x]!=-1)
ne[x]=ne[ne[x]];
}
int main(){
int m;
cin>>m;
char op[2];
for(int i=0;i<m;i++){
scanf("%s",op);
if(op[0]=='I'){
int x,y;
scanf("%d%d",&x,&y);
insertt(x,y);
}else {
int x;
scanf("%d",&x);
if(op[0]=='H')
insertt(0,x);
else
deletee(x);
}
}
for(int i=head;i!=-1;i=ne[i])
printf("%d ",e[i]);
return 0;
}