-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.h
74 lines (63 loc) · 1.62 KB
/
Node.h
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
//
// Created by isaac on 11/19/2019.
//
#ifndef NODEA_NODE_H
#define NODEA_NODE_H
/** Represents one node to be used in a linked list
Contains data (object) and reference to next in list
*/
template<typename Object>
class Node {
private:
Object item;
// This is a pointer to a Node object.
// It stores the memory address (or reference) of where the Node object is.
Node* next;
public:
/** Create new node with specified data
Have it reference null
@param newItem is data to added to new node
*/
Node(Object newItem) {
item = newItem;
next = nullptr;
}
/** Create new node with specified data
Have it reference nextNode
@param newItem is data to added to new node
@param nextNode is reference that new Node's next will hold
*/
Node(Object newItem, Node &nextNode) {
item = newItem;
// Store the memory address of the nextNode in the pointer field.
next = &nextNode;
}
/** set data field (item) of Node
@param newItem, to set item field to
*/
void setItem(Object newItem) {
item = newItem;
} // end setItem
/** get data field (item) of Node
@return item field
*/
Object getItem() {
return item;
}
/** set next field of Node
@param nextNode, to set next field to
*/
void setNext(Node &nextNode) {
next = &nextNode;
}
/** get next field Node
@return pointer to next Node
*/
Node* getNext() {
return next;
}
void setNextToNull() {
next = nullptr;
}
};
#endif //NODEA_NODE_H