标签:pre names add code char turn main std oid
#include<iostream> using namespace std; const int N = 100010; int value[N],ne[N]; int head,idx; //初始化链表 void init(){ head = -1; idx = 0; } //删除第K个数后面的数 void del(int k){ ne[k] = ne[ne[k]]; } //在第K个数后面插入x void insert(int k,int x){ value[idx] = x; ne[idx] = ne[k]; ne[k] = idx ++; } //在链表首部添加一个x void add(int x){ value[idx] = x; ne[idx] = head; head = idx ++; } int main(){ int n; cin>>n; char ch; int k ,x ; init(); while(n--){ cin>>ch; if(ch == ‘H‘){ cin>>x; add(x); } if(ch == ‘D‘){ cin>>k; if(k==0){head = ne[head];} else del(k-1); } if(ch == ‘I‘){ cin>>k>>x; insert(k-1,x); } } // cout<<idx<<" "; for(int i = head ; i != -1 ; i = ne[i]){ cout<<value[i]<<" "; } cout<<endl; return 0; }
标签:pre names add code char turn main std oid
原文地址:https://www.cnblogs.com/Flydoggie/p/12244455.html