summaryrefslogtreecommitdiff
path: root/src/user/include/cxx/structs/dllist.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/include/cxx/structs/dllist.h')
-rw-r--r--src/user/include/cxx/structs/dllist.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/user/include/cxx/structs/dllist.h b/src/user/include/cxx/structs/dllist.h
new file mode 100644
index 0000000..5783364
--- /dev/null
+++ b/src/user/include/cxx/structs/dllist.h
@@ -0,0 +1,39 @@
+#ifndef STRUCTS_DLLIST_H
+#define STRUCTS_DLLIST_H
+
+template<class data>
+class dllist {
+public:
+ class node {
+ public:
+ node *next;
+ node *prev;
+ data d;
+ node(node *next, node *prev, data d)
+ : next(next), prev(prev), d(d) {}
+ };
+ node *first;
+
+ dllist() : first(0) {}
+
+ void add_front(data d) {
+ node *const n = new node(first, 0, d);
+ if (first)
+ first->prev = n;
+ first = n;
+ }
+
+ //return previous, or zero if this is the first
+ node *remove_in_place(node *n) {
+ if (n == first)
+ first = n->next;
+ if (n->next)
+ n->next->prev = n->prev;
+ if (n->prev)
+ n->prev->next = n->next;
+ delete n;
+ return n->prev;
+ }
+};
+
+#endif \ No newline at end of file