diff options
| author | rPatrickWarner <[email protected]> | 2024-05-08 20:07:53 -0700 |
|---|---|---|
| committer | rPatrickWarner <[email protected]> | 2024-05-08 20:07:53 -0700 |
| commit | 5259785160ebfa4452507f854b30b89ed71eff75 (patch) | |
| tree | ff832914f5374a0049a6e0dd100f2391ab43e5c0 /CST 126/Homework3/SinglyLinkedList.hpp | |
| parent | init (diff) | |
| download | homework-1-reecepwarner-5259785160ebfa4452507f854b30b89ed71eff75.tar.xz homework-1-reecepwarner-5259785160ebfa4452507f854b30b89ed71eff75.zip | |
changes
Diffstat (limited to 'CST 126/Homework3/SinglyLinkedList.hpp')
| -rw-r--r-- | CST 126/Homework3/SinglyLinkedList.hpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/CST 126/Homework3/SinglyLinkedList.hpp b/CST 126/Homework3/SinglyLinkedList.hpp new file mode 100644 index 0000000..ccc2f99 --- /dev/null +++ b/CST 126/Homework3/SinglyLinkedList.hpp @@ -0,0 +1,53 @@ +#ifndef SINGLY_LINKED_LIST_HPP +#define SINGLY_LINKED_LIST_HPP + +template<typename T> + struct ListNode + { + T _data{0}; + ListNode* _next {nullptr}; + }; + +template<typename T> +struct SinglyLinkedList +{ + size_t _size {0}; + + ListNode<T>* _head{ nullptr }; + +}; + +template<typename T> +inline bool Append(SinglyLinkedList<T>* list, ListNode<T>* node) +{ + + //we have list + //we need to add node to end + //Empty set first node as head + if (list->_size == 0) + { + list->_head = node; + list->_size++; + return true; + } + + //ifnotempty + ListNode<T>* TravelNode = nullptr; + for (TravelNode = list->_head; TravelNode->_next!= nullptr;) + { + TravelNode = TravelNode->_next; + } + TravelNode->_next = node; + return true;//ifsuccess + +} + + + + + + + + + +#endif
\ No newline at end of file |