diff options
Add Seminar04
1 files changed, 31 insertions, 0 deletions
| -rw-r--r-- | Seminar04/linked-list-utils.h | 31 |
diff --git a/Seminar04/linked-list-utils.h b/Seminar04/linked-list-utils.h new file mode 100644 index 0000000..8e0fa23 --- /dev/null +++ b/Seminar04/linked-list-utils.h @@ -0,0 +1,31 @@ +#include<iostream> +#include<initializer_list> + +template<class T> +struct LinkedListNode { + T data; + LinkedListNode<T>* next; + + LinkedListNode(const T& elem, LinkedListNode<T>* n = nullptr) : data{elem}, next {n} {} +}; + +template<class T> +void printLinkedList(const LinkedListNode<T>* ll) { + const LinkedListNode<T>* iterate = ll; + + while(iterate) { + std::cout << iterate->data << " "; + iterate = iterate->next; + } + + std::cout << std::endl; +} + +template<class T> +void freeList(LinkedListNode<T>* ll) { + while(ll) { + LinkedListNode<T>* toDelete = ll; + ll = ll->next; + delete toDelete; + } +}
\ No newline at end of file |
