From 7eee5a78005a9a569186d2c8b4b645a818ab9bf1 Mon Sep 17 00:00:00 2001 From: Stoycho Kyosev Date: Sun, 6 Oct 2024 07:04:44 -0400 Subject: Cleanup --- Seminar04/linked-list-utils.h | 74 ------------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 Seminar04/linked-list-utils.h (limited to 'Seminar04/linked-list-utils.h') diff --git a/Seminar04/linked-list-utils.h b/Seminar04/linked-list-utils.h deleted file mode 100644 index bf093ba..0000000 --- a/Seminar04/linked-list-utils.h +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include - -template -struct LinkedListNode { - T data; - LinkedListNode* next; - - LinkedListNode(const T& elem, LinkedListNode* n = nullptr) : data{elem}, next {n} {} -}; - -template -void printLinkedList(const LinkedListNode* ll) { - const LinkedListNode* iterate = ll; - - while(iterate) { - std::cout << iterate->data << " "; - iterate = iterate->next; - } - - std::cout << std::endl; -} - -template -void printLinkedList(const LinkedListNode* ll, void (*print)(T)) { - const LinkedListNode* iterate = ll; - - while(iterate) { - print(iterate->data); - iterate = iterate->next; - } - - std::cout << std::endl; -} - -template -void printLinkedList(const LinkedListNode* ll, void (*print)(const T&)) { - const LinkedListNode* iterate = ll; - - while(iterate) { - print(iterate->data); - iterate = iterate->next; - } - - std::cout << std::endl; -} - -template -LinkedListNode* fromList(const std::initializer_list& l) { - LinkedListNode* toReturn = nullptr; - LinkedListNode* iter = nullptr; - - for(const auto& elem : l) { - LinkedListNode* toInsert = new LinkedListNode(elem); - if(iter == nullptr) { - toReturn = toInsert; - iter = toInsert; - } - else { - iter->next = toInsert; - iter = iter->next; - } - } - return toReturn; -} - -template -void freeList(LinkedListNode* ll) { - while(ll) { - LinkedListNode* toDelete = ll; - ll = ll->next; - delete toDelete; - } -} \ No newline at end of file -- cgit v1.3.1-26-gb76a