-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.cpp
More file actions
99 lines (95 loc) · 2.18 KB
/
node.cpp
File metadata and controls
99 lines (95 loc) · 2.18 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
91
92
93
94
95
96
97
98
99
#include "node.h"
PNode CreateNode (string nword){
PNode NewNode = new Node;
NewNode->word = nword;
NewNode->count = 1;
NewNode->next = NULL;
return NewNode;
}
void prov(string &a){
int l = a.length();
for (int i = 0; i < l; ++i){
if(a[i] == '.'){
a.erase(i,1);
}
if(a[i] == ','){
a.erase(i,1);
}
if(a[i] == '?'){
a.erase(i,1);
}
if(a[i] == '!'){
a.erase(i,1);
}
if(a[i] == '"'){
a.erase(i,1);
}
if(a[i] == '('){
a.erase(i,1);
}
if(a[i] == ')'){
a.erase(i,1);
}
}
}
void AddFirst (PNode &Head, PNode NewNode){ // добавление в начало списка
NewNode->next = Head;
Head = NewNode;
}
void AddAfter (PNode p, PNode NewNode) // добавление узла после заданного
{
NewNode->next = p->next;
p->next = NewNode;
}
void AddBefore(PNode &Head, PNode p, PNode NewNode) // добавление узла перед заданным
{
PNode q = Head;
if (Head == p) {
AddFirst(Head, NewNode); // вставка перед первым узлом
return;
}
while (q && q->next != p){ // ищем узел, за которым следует p
q = q->next;
}
if (q){ // если нашли такой узел,
AddAfter(q, NewNode); // добавить новый после него
}
}
void AddLast(PNode &Head, PNode NewNode) // добавление узла в конец списка
{
PNode q = Head;
if (Head == NULL) { // если список пуст,
AddFirst(Head, NewNode); // вставляем первый элемент
return;
}
while (q->next) q = q->next; // ищем последний элемент
AddAfter(q, NewNode);
}
PNode Find (PNode Head, string NewWord){ // поиск узла по значению
PNode q = Head;
while (q && q->word.compare(NewWord)){
q = q->next;
}
return q;
}
PNode FindPlace (PNode Head, string NewWord)
{
PNode q = Head;
while (q && (q->word.compare(NewWord) > 0)){
q = q->next;
}
return q;
}
void DeleteNode(PNode &Head, PNode OldNode){
PNode q = Head;
if(Head == OldNode){
Head = OldNode->next;
}else{
while(q && q->next != OldNode){
q = q->next;
}
if(q == NULL) return;
q->next = OldNode->next;
}
delete OldNode;
}