diff options
| author | Chanin Timbal <[email protected]> | 2024-06-06 20:11:53 -0700 |
|---|---|---|
| committer | Chanin Timbal <[email protected]> | 2024-06-06 20:11:53 -0700 |
| commit | a1d340b239eeb75159640e6b3e2bdb5586251e55 (patch) | |
| tree | 5d1a00bd6d9aa56b711e18b1476dd73f1ac53dd2 /CST 126/Homework_3 | |
| parent | Created node struct and singlylinkedlist struct, and append function. Also co... (diff) | |
| download | homework-1-chaninnohea-a1d340b239eeb75159640e6b3e2bdb5586251e55.tar.xz homework-1-chaninnohea-a1d340b239eeb75159640e6b3e2bdb5586251e55.zip | |
Created Prepend function for Homework 3 - Successful unit test for prepend function
Diffstat (limited to 'CST 126/Homework_3')
| -rw-r--r-- | CST 126/Homework_3/SinglyLinkedList.hpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/CST 126/Homework_3/SinglyLinkedList.hpp b/CST 126/Homework_3/SinglyLinkedList.hpp index 8fbf2b2..38c0072 100644 --- a/CST 126/Homework_3/SinglyLinkedList.hpp +++ b/CST 126/Homework_3/SinglyLinkedList.hpp @@ -40,6 +40,22 @@ bool Append(SinglyLinkedList* list, ListNode* node) { return true; } +bool Prepend(SinglyLinkedList* list, ListNode* node) { + //if empty + if (list->_size == 0) + { + list->_head = node; + list->_size++; + return true; + } + + //if not empty + ListNode* travel = list->_head; + list->_head = node; + node->_next = travel; + + return true; +} #endif |