-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.cpp
More file actions
76 lines (64 loc) · 1.68 KB
/
Copy pathNode.cpp
File metadata and controls
76 lines (64 loc) · 1.68 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
#include "Node.h"
//Key : symbol. Value : word
string Node::getWord() { return word; }
long Node::getSymbol() { return symbol; }
//Add to the Node childrens list the Node n
//If there is already a symbol s in the childre list, it just update his linked word
Node* Node::addNode(string w, long s) {
for (vector<Node *>::iterator it = childrens.begin(); it != childrens.end(); ++it)
{
if (((*it)->symbol == s)) {
(*it)->word = w;
return (*it);
}
}
Node * n = new Node(w, s);
childrens.push_back(n);
return n;
}
//Remove the first children with the symbol s from Node childrens list. Return true if the remove was sucessfull, otherwise false
bool Node::removeNode(long s) { //True if removed, else false
for (vector<Node *>::iterator it = childrens.begin(); it != childrens.end(); ++it)
{
if (((*it)->symbol == s)) {
childrens.erase(it);
return true;
}
}
return false;
}
//Return true if symbol s is present at least one time in the Node childrens list. Else return false
bool Node::isPresent(long s) {
for (vector<Node *>::iterator it = childrens.begin(); it != childrens.end(); ++it)
{
if (((*it)->symbol == s)) {
return true;
}
}
return false;
}
//Return the children of this node with the symbol s. Otherwise return NULL
Node* Node::getChildren(long s) {
for (vector<Node *>::iterator it = childrens.begin(); it != childrens.end(); ++it)
{
if (((*it)->symbol == s)) {
return (*it);
}
}
return NULL;
}
vector <Node*> Node::getChildrens() {
return childrens;
}
bool Node::hasChildrens() {
return childrens.size() != 0;
}
//Constructor of Node. w is the word linked to the symbol s
Node::Node(string w, long s)
{
word = w;
symbol = s;
}
Node::~Node()
{
}