summaryrefslogtreecommitdiff
path: root/src/user/include/cxx/structs/dllist.h
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2021-03-04 19:11:42 -0500
committerBenji Dial <benji6283@gmail.com>2021-03-04 19:11:42 -0500
commit406af09ade55553e2b064506c3ba3c89bd965d73 (patch)
treedd6da93bc329d6b1097aa1afcde2af19491dfc8e /src/user/include/cxx/structs/dllist.h
parent86af7f631080bc4b45846bd7f382c4cedcbec2b4 (diff)
downloadportland-os-406af09ade55553e2b064506c3ba3c89bd965d73.tar.gz
start of a c++ widget toolkit, c++ runtime
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