-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataNode.cpp
More file actions
60 lines (49 loc) · 1.42 KB
/
DataNode.cpp
File metadata and controls
60 lines (49 loc) · 1.42 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
// DataNode.cpp
#include "DataNode.h"
DataNode::DataNode() {
data = "";
key = "";
next = nullptr;
} // end constructor
DataNode::DataNode(std::string word) {
data = word;
// update the key based on the new word inserted
key = setKey();
next = nullptr;
} // end parameterized constructor
/* Function: setKey
* Purpose: to update the value of the word's key based on the value of the data (the word itself) when it is updated
* the key is either only the first letter or the first two letters based on the length of the string
* Return value: the string for key
*/
std::string DataNode::setKey() {
std::string key;
key = "";
if (data.size() >= 1) {
// use the substring method to get the first two letters of the word as key
if (data.size() > 2) {
key = data.substr(0, 2); // from position = 0 and length = 2
} // end if
else {
key = data;
} // end if-else
} // end if
return key;
} // end setKey
// access methods
std::string DataNode::getData() {
return data;
} // end getData
void DataNode::setData(std::string word) {
data = word;
key = setKey();
} // end setData
std::shared_ptr<DataNode> DataNode::getNext() {
return next;
} // end getNext
void DataNode::setNext(std::shared_ptr<DataNode> node) {
next = node;
} // end setNext
std::string DataNode::getKey() {
return key;
} // end getKey