-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.cpp
More file actions
58 lines (56 loc) · 842 Bytes
/
list.cpp
File metadata and controls
58 lines (56 loc) · 842 Bytes
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
#include <iostream>
using namespace std;
struct node{
char data;
node *prev,*next;
};
node *gaurd;
void print (){
for(node *i=gaurd->next;;i=i->next){
cout<<i->data;
if(i->next=gaurd)
break;
}
}
void rem(node *p){
p->prev->next=p->next;
p->next->prev=p->prev;
}
void add(node *p,char x){
node *t=new node;
t->data=x;
t->next=p->next;
t->prev=p;
p->next=t;
t->next->prev=t;
}
int main(){
gaurd=new node;
gaurd->next=gaurd->prev=gaurd;
cin>>n;
node *cur=gaurd;
while(n--){
char c;
cin>>c;
if(c=='L'){
if(cur!=gaurd)
cur=cur->prev;
}
else if(c=='R'){
if(cur->next!=gaurd)
cur=cur->next;
}
else if(c=='B'){
if(cur!=gaurd){
rem(cur);
cur=cur->prev;
}
}
else{
add(cur,c);
cur=cur->next;
}
}
print();
return 0;
}