-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.h
105 lines (81 loc) · 2.41 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
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
//
// Created by luise on 5/3/2020.
//
#ifndef ALGORITHMS_NODE_H
#define ALGORITHMS_NODE_H
#include <iostream>
template<class T>
class Node{
private:
// Each node contains:
Node<T>* next; // Node pointer, pointing to the next Node in the list
Node<T>* previous; // Node pointer, pointing to the previous node in the list
T data; // Data of type T
public:
// Default constructor
Node();
// Constructor with data value passed into it
explicit Node(T);
Node(const Node<T>&);
// Copy constructor
Node(const Node<T>&,Node<T>*,Node<T>*);
// Set functions used to re/define Node variables
void setData(T*);
void setNextNode(Node<T>*);
void setPreviousNode(Node<T>*);
// Get functions used to return Node variables
T* getData();
Node<T>* getNextNode();
Node<T>* getPreviousNode();
// Node destructor
~Node();
};
// Default constructor : initializes Node
template<class T>
Node<T>::Node() : next(nullptr), previous(nullptr){
}
// parameter "aValue" of type T is used to declare data value
template<class T>
Node<T>::Node(T aValue) : next(nullptr), previous(nullptr), data(aValue){
}
template<class T>
Node<T>::Node(const Node<T>& data2) : next(nullptr), previous(nullptr), data(data2.data){
}
template<class T>
Node<T>::Node(const Node<T>& aData, Node<T>* aNext, Node<T>* aPrevious) :
data(aData.data), next(aNext), previous(aPrevious){
}
// Set current node data equal to x
template<class T>
void Node<T>::setData(T* x){
this->data = x;
}
// Get current node data
template<class T>
T* Node<T>::getData(){
return &data;
}
// Set the next node in the list using parameter "setNext" of type Node<T>*
template<class T>
void Node<T>::setNextNode(Node<T>* setNext){
this->next = setNext;
}
// Set the previous node in the list using parameter "setPrev" of type Node<T>*
template<class T>
void Node<T>::setPreviousNode(Node<T>* setPrev){
this->previous = setPrev;
}
// get" or return the next node in the list
template<class T>
Node<T>* Node<T>::getNextNode(){
return this->next;
}
// Used to "get" or return the previous node in the list
template<class T>
Node<T>* Node<T>::getPreviousNode(){
return this->previous;
}
// Default Node destructor
template<class T>
Node<T>::~Node<T>()= default;
#endif //ALGORITHMS_NODE_H