blob: bd49510edaa6d58a98b600e7ed3be15d68cab3c5 (
plain)
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
|
#include "linked_list.h"
template <typename T>
llist<T>::llist () {
this->length = 0;
this->cur = this->head = new link<T>;
this->tail = new link<T>;
head->after = tail;
tail->before = head;
}
template <typename T>
link<T>::~link () {
this.unlink();
}
template <typename T>
void link<T>::unlink () {
if (this->before != nullptr) this->before->after = this->after;
if (this->after != nullptr) this->after->before = this->before;
}
template <typename T>
void llist<T>::push(T& val) {
auto l = new link<T>(val);
l->after = FIRST(this);
FIRST(this) = l;
l->after->before = l;
l->before = this->head;
++this->length;
// TODO do I want to change that?
this->cur = l;
}
|