diff --git a/src/linked-list.cpp b/src/linked-list.cpp new file mode 100644 index 0000000..d15a6ae --- /dev/null +++ b/src/linked-list.cpp @@ -0,0 +1,16 @@ +#include "linked-list.hpp" + +template int insertNode(LinkedList *list, T data) { + LinkedList *node = new LinkedList; + + node->data = data; + + if (list == nullptr) { + node->next = list; + list = node; + } else { + list->next = node; + } + + return 0; +} diff --git a/src/linked-list.hpp b/src/linked-list.hpp new file mode 100644 index 0000000..4586745 --- /dev/null +++ b/src/linked-list.hpp @@ -0,0 +1,8 @@ +template +struct LinkedList { + T data; + struct LinkedList* next; +}; + +template +int insertNode(LinkedList *, T);