aboutsummaryrefslogtreecommitdiff
path: root/list.cpp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2021-11-20 22:35:32 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2021-11-20 22:35:32 +0000
commita495bd9c64fc860fa4bb6a9c80f50049ec62b6d3 (patch)
tree3e101c27a2b51840191e8d9a939f3c6278bcd733 /list.cpp
parent73e2e18839abcbb5f48ff903840e9e6069a5d8fb (diff)
downloadalgorithms-a495bd9c64fc860fa4bb6a9c80f50049ec62b6d3.tar.gz
algorithms-a495bd9c64fc860fa4bb6a9c80f50049ec62b6d3.tar.bz2
algorithms-a495bd9c64fc860fa4bb6a9c80f50049ec62b6d3.zip
(list)+list.cpp file
Will have all the singly linked list algorithms I can think of, using the structure I have defined (template based singly linked list) and the simple append function I have added that also acts as the main method of creating an instance.
Diffstat (limited to 'list.cpp')
-rw-r--r--list.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/list.cpp b/list.cpp
new file mode 100644
index 0000000..8c671a1
--- /dev/null
+++ b/list.cpp
@@ -0,0 +1,40 @@
+/* list.cpp
+ * Date: 2021-11-20
+ * Author: Aryadev Chavali
+ */
+
+#include <cstdio>
+#include <cstdlib>
+
+template <typename T>
+struct List
+{
+ T value;
+ struct List<T> *next;
+};
+
+template <typename T>
+struct List<T> *append(struct List<T> *lst, T value)
+{
+ struct List<T> *node;
+ if (lst == NULL)
+ {
+ node = new List<T>;
+ node->value = value;
+ node->next = NULL;
+ return node;
+ }
+
+ for (node = lst; node->next != NULL; node = node->next)
+ continue;
+
+ node->next = new List<T>;
+ node->next->value = value;
+ node->next->next = NULL;
+ return lst;
+}
+
+int main(void)
+{
+ return 0;
+}