diff options
| author | Chanin Timbal <[email protected]> | 2024-06-05 15:25:47 -0700 |
|---|---|---|
| committer | Chanin Timbal <[email protected]> | 2024-06-05 15:25:47 -0700 |
| commit | 4646ce2a21cd6cba10af60cc3e821eb83ee7e5f9 (patch) | |
| tree | e540a264b95d2aaec40709cb79db67345100b8e3 /CST 126/Homework_3/SinglyLinkedList.hpp | |
| parent | Restored completed Homework 1 that was accidentally completed, Code should be... (diff) | |
| download | homework-1-chaninnohea-4646ce2a21cd6cba10af60cc3e821eb83ee7e5f9.tar.xz homework-1-chaninnohea-4646ce2a21cd6cba10af60cc3e821eb83ee7e5f9.zip | |
Created node struct and singlylinkedlist struct, and append function. Also complete Unit Testing for this section.
Diffstat (limited to 'CST 126/Homework_3/SinglyLinkedList.hpp')
| -rw-r--r-- | CST 126/Homework_3/SinglyLinkedList.hpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/CST 126/Homework_3/SinglyLinkedList.hpp b/CST 126/Homework_3/SinglyLinkedList.hpp new file mode 100644 index 0000000..8fbf2b2 --- /dev/null +++ b/CST 126/Homework_3/SinglyLinkedList.hpp @@ -0,0 +1,45 @@ +#ifndef SINGLY_LINKED_LIST_HPP +#define SINGLY_LINKED_LIST_HPP + + +struct ListNode { + int _data = 0; + ListNode* _next = nullptr; +}; + +struct SinglyLinkedList { + size_t _size; + ListNode* _head = nullptr; +}; + + +//SinglyLinkedList singlylinkedlist{}; +//ListNode listnode{}; +// +//listnode._data = 1; +//singlylinkedlist._head = &listnode; + +bool Append(SinglyLinkedList* list, ListNode* node) { + + //if empty + if (list->_size == 0) + { + list->_head = node; + list->_size++; + return true; + } + + //if not empty + ListNode* travel = nullptr; + for (travel = list->_head; travel->_next != nullptr;) + { + travel = travel->_next; + } + + travel->_next = node; + return true; +} + + + +#endif |