From a495bd9c64fc860fa4bb6a9c80f50049ec62b6d3 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sat, 20 Nov 2021 22:35:32 +0000 Subject: (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. --- list.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 list.cpp 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 +#include + +template +struct List +{ + T value; + struct List *next; +}; + +template +struct List *append(struct List *lst, T value) +{ + struct List *node; + if (lst == NULL) + { + node = new List; + node->value = value; + node->next = NULL; + return node; + } + + for (node = lst; node->next != NULL; node = node->next) + continue; + + node->next = new List; + node->next->value = value; + node->next->next = NULL; + return lst; +} + +int main(void) +{ + return 0; +} -- cgit v1.2.3-13-gbd6f