-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist.h
49 lines (43 loc) · 1.13 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
#pragma once
namespace firefly::std {
/**
* Doubly linked list node
* @param <T> The data's type
*/
template <typename T>
struct list_node {
/**
* Next node in the list
*/
list_node<T>* next;
/**
* Previous node in the list
*/
list_node<T>* prev;
/**
* Node data
*/
T data;
/**
* Construct a new list
*/
list_node() : next { this }, prev { this } {}
/**
* Adds a node following this one
* @param nx The new node to add
*/
void add(list_node<T>* nx) {
nx->next = next;
nx->prev = this;
next->prev = nx;
next = nx;
}
/**
* Removes this node from the list
*/
void remove() {
prev->next = next;
next->prev = prev;
}
};
} // namespace firefly::std