diff options
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 |