-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathList.cpp
More file actions
50 lines (44 loc) · 933 Bytes
/
Copy pathList.cpp
File metadata and controls
50 lines (44 loc) · 933 Bytes
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
#include "List.h"
#include <stdio.h>
template<class T>
void List<T>::add(T value)
{
Node<T> * ptr = &m_root;
while( ptr->getNext() != nullptr )
{
ptr = ptr->getNext();
}
Node<T> * newEntry = new Node<T>( value );
ptr->setNext( newEntry );
m_size++;
}
template<class T>
void List<T>::remove(T value)
{
Node<T>* ptr = &m_root;
while( ptr->getNext() != nullptr )
{
if( ptr->getNext()->getValue() == value )
{
//Remove
Node<T> * r = ptr->getNext();
ptr->setNext( r->getNext() );
delete r;
m_size--;
continue;
}
ptr = ptr->getNext();
}
}
template<class T>
void List<T>::print()
{
Node<T> * ptr = m_root.getNext();
while( ptr != nullptr )
{
printf("%d, ", ptr->getValue() );
ptr = ptr->getNext();
}
printf("\n");
}
template class List<int>;