aboutsummaryrefslogtreecommitdiff
path: root/linked_list.cpp
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-19 00:27:43 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-19 00:27:43 +0100
commitaae3b8bfb83abec0f1bb8e4c854c156c03be5ca8 (patch)
tree305f1287a8cc6a896318a4de5f2b43686e7223b3 /linked_list.cpp
parentMade to compile as C++. (diff)
downloadcalp-aae3b8bfb83abec0f1bb8e4c854c156c03be5ca8.tar.gz
calp-aae3b8bfb83abec0f1bb8e4c854c156c03be5ca8.tar.xz
Started full rewrite in C++.
Diffstat (limited to 'linked_list.cpp')
-rw-r--r--linked_list.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/linked_list.cpp b/linked_list.cpp
new file mode 100644
index 00000000..bd49510e
--- /dev/null
+++ b/linked_list.cpp
@@ -0,0 +1,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;
+}