-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoublyLinkedList.cpp
More file actions
58 lines (50 loc) · 1.04 KB
/
Copy pathdoublyLinkedList.cpp
File metadata and controls
58 lines (50 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e5+10,M=1e5+10,INF=0x3f3f3f3f,MOD=1e9+7;
const double EPS=1e-8;
int n,m;
int no[N],le[N],ri[N],idx;
void insert(int k,int x){
no[idx]=x;
le[idx]=k,ri[idx]=ri[k];
le[ri[k]]=idx,ri[k]=idx++;
}
void remove(int x){
le[ri[x]]=le[x];
ri[le[x]]=ri[x];
}
int main(){
scanf("%d",&n);
ri[0]=1,le[1]=0;
idx=2;
while(n--){
char op[3];
scanf("%s",op);
int k,x;
if(op[0]=='L'){
scanf("%d",&x);
insert(0,x);
}
else if(op[0]=='R'){
scanf("%d",&x);
insert(le[1],x);
}
else if(op[0]=='D'){
scanf("%d",&k);
remove(k+1);
}
else if(!strcmp(op,"IL")){
scanf("%d%d",&k,&x);
insert(le[k+1],x);
}
else {
scanf("%d%d",&k,&x);
insert(k+1,x);
}
}
for(int i=ri[0];i!=1;i=ri[i]){
printf("%d ",no[i]);
}
}