Added destructor for CircularLinkedList

This commit is contained in:
Alvin Philips 2021-10-31 22:23:33 +05:30
parent f7d7da69b9
commit 797f1f4327

View File

@ -67,6 +67,20 @@ class CircularLinkedList {
root = nullptr;
end = nullptr;
}
/**
* @brief Cleans up memory
*/
~CircularLinkedList() {
if (root == nullptr) {
return;
}
Node* node = root;
do {
Node* temp = node;
node = node->next;
delete (temp);
} while (node != root);
}
/**
* @brief Inserts all the values from a vector into the Circular Linked List
* @details Goes through each element in the vector sequentially, inserting
@ -238,6 +252,7 @@ void test4() {
a.insert(start);
assert(a.values(start) == res);
a.print(start);
delete (start); ///< Free memory of the Node
std::cout << "TEST PASSED!\n\n";
}