aboutsummaryrefslogtreecommitdiff
path: root/CST 126/Homework_3/SinglyLinkedList.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'CST 126/Homework_3/SinglyLinkedList.hpp')
-rw-r--r--CST 126/Homework_3/SinglyLinkedList.hpp45
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