-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.cpp
More file actions
70 lines (55 loc) · 922 Bytes
/
list.cpp
File metadata and controls
70 lines (55 loc) · 922 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <cassert>
namespace my {
namespace {
template<typename T>
struct Node {
Node* next;
Node* prev;
T data;
Node(T data) {
this->data = data;
this->prev = NULL;
this->next = NULL;
};
};
}
template<class T>
class List {
public:
List() {
_head = NULL;
_tail = NULL;
}
void add(const T& data) {
Node<T>* node = new Node<T>(data);
if( _tail == NULL) {
_head = node;
_tail = node;
}
else {
_tail->next = node;
node->prev = _tail;
_tail = node;
}
}
void print() {
for( Node<T>* node = _head; node != NULL; node = node->next) {
std::cout << node->data << std::endl;
}
}
private:
Node<T>* _head;
Node<T>* _tail;
};
};
int main()
{
std::cout << "hey" << std::endl;
my::List<int>* list = new my::List<int>();
list->add(1);
list->add(2);
list->add(3);
list->print();
return 0;
}