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.hpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/CST 126/Homework_3/SinglyLinkedList.hpp b/CST 126/Homework_3/SinglyLinkedList.hpp
index 75f9530..9046d58 100644
--- a/CST 126/Homework_3/SinglyLinkedList.hpp
+++ b/CST 126/Homework_3/SinglyLinkedList.hpp
@@ -37,6 +37,7 @@ bool Append(SinglyLinkedList* list, ListNode* node) {
}
travel->_next = node;
+ list->_size++;
return true;
}
@@ -55,6 +56,7 @@ bool Prepend(SinglyLinkedList* list, ListNode* node) {
list->_head = node;
node->_next = travel;
+ list->_size++;
return true;
}
@@ -120,6 +122,7 @@ bool InsertAfter(SinglyLinkedList* list, ListNode* nodeBefore, ListNode* nodeToI
nodeToInsert->_next = nodeBefore->_next;
nodeBefore->_next = nodeToInsert;
+ list->_size++;
return true;
}
@@ -147,6 +150,7 @@ bool InsertBefore(SinglyLinkedList* list, ListNode* node, ListNode* nodeToInsert
nodeToInsert->_next = node;
temp->_next = nodeToInsert;
+ list->_size++;
return true;
}
@@ -172,7 +176,32 @@ bool Clear(SinglyLinkedList* list)
return true;
}
+bool ExtractFrom(SinglyLinkedList* list, ListNode* NodetoExtract)
+{
+ if (list->_size == 0 || NodetoExtract == nullptr)
+ return false;
+
+ if (NodetoExtract == list->_head)
+ {
+ list->_head = NodetoExtract->_next;
+ delete NodetoExtract;
+ list->_size--;
+ return true;
+ }
+
+ ListNode* NodeBefore = list->_head;
+ while (NodeBefore->_next != NodetoExtract)
+ {
+ NodeBefore = NodeBefore->_next;
+ }
+
+ NodeBefore->_next = NodetoExtract->_next;
+ delete NodetoExtract;
+ list->_size--;
+
+ return true;
+}
#endif