-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedList.cpp
114 lines (99 loc) · 2.07 KB
/
LinkedList.cpp
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
106
107
108
109
110
111
112
113
114
#include "LinkedList.h"
template<class T>
LinkedList<T>::LinkedList(){
this->start = 0;
}
template<class T>
void LinkedList<T>::push(T newelement){
element* tmp = new element;
tmp->value = newelement;
tmp->prev = 0;
tmp->next = start;
if(start != 0)
start->prev = tmp ;
start = tmp;
}
template<class T>
void LinkedList<T>::pop(){
element *tmp = start;
while(start!=0){
start=tmp->prev;
delete tmp;
}
}
template<class T>
void LinkedList<T>::pop(T element_to_pop) {
element *tmp=start;
if (start == 0) return;
while(tmp!=0) {
if (tmp->value == element_to_pop) {
if (start->value == element_to_pop)
start = tmp->next;
if (tmp->next != 0)
(tmp->next)->prev = tmp->prev;
if (tmp->prev != 0)
(tmp->prev)->next = tmp->next;
delete tmp;
return;
}
else return;
tmp=tmp->next;
};
}
//UNUSED, my project never required it.
/*template<class T>
void LinkedList<T>::pop(unsigned short index) {
element* tmp = start;
for (int i=0;i<index;i++){
tmp=tmp->next;
};
delete tmp;
}*/
template<class T>
T LinkedList<T>::find(int index){
element *tmp=start;
int i=0;
while(tmp!=0 && i<index) {
tmp=tmp->next;
i++;
}
if (tmp != 0)
return tmp->value;
}
template<class T>
T LinkedList<T>::call(){
element *tmp=start;
return tmp->value;
}
template<class T>
T LinkedList<T>::call(T value){
element *tmp=start;
while(tmp!=0) {
if (tmp->value == value) {
return tmp->value;
}
tmp=tmp->next;
}
};
template<class T>
bool LinkedList<T>::checkforvalue(T check_for_value){
element *tmp=start;
while(tmp!=0) {
if (tmp->value == check_for_value) {
return true;
}
tmp=tmp->next;
}
return false;
};
template<class T>
int LinkedList<T>::length(){
int i=0;
element *tmp=start;
while (tmp!=0) {
i++;
tmp=tmp->next;
}
return i;
}
//template class LinkedList<int>; <- add class templates here