-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.cpp
More file actions
90 lines (71 loc) · 1.21 KB
/
list.cpp
File metadata and controls
90 lines (71 loc) · 1.21 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <bits/stdc++.h>
using namespace std;
struct Node{
Node* next;
int count;
string word;
};
typedef Node* pNode;
pNode add(string w) {
pNode New = new Node;
New->next = nullptr;
New->count = 1;
New->word = w;
return New;
}
void addFirst(pNode& head, pNode new_) {
new_->next = head;
head = new_;
}
void addAfter(pNode p, pNode New) {
New->next = p->next;
p->next = New;
}
void addBefore(pNode p, pNode New, pNode head) {
if(p == head) {
addFirst(head, New);
return;
}
pNode after = head;
while(p && after->next != p) {
after = after->next;
}
if(after) {
addAfter(after, New);
}
}
void addLast(pNode New, pNode& head) {
if(head == nullptr) {
addFirst(head, New);
return;
}
pNode after = head;
while(after && after->next != nullptr) {
after = after->next;
}
addAfter(after, New);
}
pNode find(pNode head, string w) {
pNode p = head;
while(p && p->word != w) {
p = p->next;
}
return p;
}
int main() {
int n; cin >> n;
pNode HEAD = add("");
while(n--) {
string s; cin >> s;
if(find(HEAD, s) != nullptr) {
pNode q = add(s);
addAfter(HEAD, q);
} else {
pNode q = find(HEAD, s);
}
/*string command; cin >> command;
if(command == "add") {
}
*/
}
}