-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.cpp
More file actions
74 lines (68 loc) · 1.4 KB
/
LinkedList.cpp
File metadata and controls
74 lines (68 loc) · 1.4 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<bits/stdc++.h>
using namespace std;
template<class T>
class LinkedList{
private:
struct node{
T data;
bool begin, end;
node *next, *last;
};
node first;
node *p = &first;
public:
LinkedList(){
p->begin = 1;
p->end = 1;
p->data = -1;
}
void print_begin_to_end(){
if(first.end) return;
node temp = *first.next;
while(true){
cout<<temp.data;
if(temp.end) break;
temp = *temp.next;
}
}
void insert(T data){
node* temp = (node*) malloc(sizeof(node));
temp->data = data;
temp->last = p;
if(p->end){
p->end = 0;
p->next = temp;
temp->end = 1;
p = temp;
p->begin = 0;
}
else{
temp->next = p->next;
p->next = temp;
temp->last = p;
temp->begin = 0;
temp->end = 0;
p = temp;
}
}
void to_right(){
if(p->end) return;
p = p->next;
}
void to_left(){
if(p->begin) return;
p = p->last;
}
};
int main(){
string s;cin>>s;
int n = 0;
LinkedList<char> a;
for(auto x: s){
if(x == 'L') a.to_left();
else if(x == 'R') a.to_right();
else a.insert(x), n++;
}
a.print_begin_to_end();
return 0;
}