-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.h
82 lines (71 loc) · 1.09 KB
/
list.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
template<class T>
class Node{
private:
T value;
Node<T>* next;
public:
Node(T inp=0);
T getValue();
Node<T>* getNext();
void setNext(Node<T>* hook);
};
template<class T>
class List{
private:
Node<T>* head;
int numElements;
int maxElements;
public:
List(int maxelements);
void insert(Node<T>& neo);
Node<T> pop();
int length();
};
//
//
//
// Implementation of the class methods are below
//
//
//
template<class T>
Node<T>::Node(T inp){
value = inp;
next = NULL;
}
template<class T>
T Node<T>::getValue(){
return value;
}
template<class T>
Node<T>* Node<T>::getNext(){
return next;
}
template<class T>
void Node<T>::setNext(Node* hook){
next = hook;
}
template<class T>
List<T>::List(int maxelements){
head = NULL;
maxElements = maxelements;
numElements = 0;
}
template<class T>
void List<T>::insert(Node<T>& neo){
neo.setNext(head);
head = &neo;
numElements++;
}
template<class T>
Node<T> List<T>::pop(){
Node<T>* out = head;
if(head != NULL)
head = head->getNext();
numElements--;
return *out;
}
template<class T>
int List<T>::length(){
return numElements;
}