-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_tree.cpp
More file actions
124 lines (103 loc) · 2.36 KB
/
my_tree.cpp
File metadata and controls
124 lines (103 loc) · 2.36 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "my_tree.h"
#include <iostream>
Node::Node(DictionaryTree* _base, wchar_t _c)
{
base = _base;
c = _c;
freq = 0;
}
Node* Node::addChild(wchar_t _c)
{
Node* node = new Node(base, _c);
node->index = base->size;
base->size++;
children.push_back(node);
return node;
}
Node* Node::searchInChildren(wchar_t _c)
{
for (Node* node : children)
if (node->c == _c)
return node;
return nullptr;
}
std::list<Node*>& Node::getChildren() {
return children;
}
DictionaryTree::DictionaryTree() {
size = INITIAL_DICTIONARY_SIZE/*256*/;
}
Node* DictionaryTree::addChild(wchar_t _c)
{
Node* node = new Node(this, _c);
children.push_back(node);
/*if (_c > INITIAL_DICTIONARY_SIZE)
std::cout << " " << (int) _c << ' ';*/
node->index = _c;
return node;
}
Node* DictionaryTree::searchInChildren(wchar_t _c)
{
for (Node* node : children)
if (node->c == _c)
return node;
return nullptr;
}
std::list<Node*>& DictionaryTree::getChildren() {
return children;
}
// Node::Node(Tree* _base, wchar_t _c)
// {
// base = _base;
// firstChild = nullptr;
// nextSibling = nullptr;
// c = _c;
// index = base->size;
// base->size++;
// freq = 1;
// }
// Node* Node::setFirstChild (wchar_t _c)
// {
// Node* node = new Node(base, _c);
// firstChild = node;
// return node;
// }
// Node* Node::setNextSibling (wchar_t _c)
// {
// Node* node = new Node(base, _c);
// nextSibling = node;
// return node;
// }
// Node* Node::search(std::wstring_view _s)
// {
// if (_s[0] == c)
// {
// if (_s.size() == 1) return this;
// if (firstChild) return firstChild->search(_s.substr(1, _s.size()));
// return nullptr;
// }
// else
// {
// if (nextSibling) return nextSibling->search(_s.substr(1, _s.size()));
// return nullptr;
// }
// }
// Node* Node::search(wchar_t _c)
// {
// if (_c == c) return this;
// if (nextSibling) return nextSibling->search(_c);
// return nullptr;
// }
// Tree::Tree (wchar_t _c)
// {
// Node* child = new Node(this, _c);
// firstChild = child;
// }
// Node* Tree::search(std::wstring_view _s)
// {
// return firstChild->search(_s);
// }
// Node* Tree::search(wchar_t _c)
// {
// return firstChild->search(_c);
// }