From 406af09ade55553e2b064506c3ba3c89bd965d73 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Thu, 4 Mar 2021 19:11:42 -0500 Subject: start of a c++ widget toolkit, c++ runtime --- src/user/include/cxx/structs/dllist.h | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/user/include/cxx/structs/dllist.h (limited to 'src/user/include/cxx/structs/dllist.h') 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 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 -- cgit v1.2.3