mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-05-08 23:23:05 +08:00
Added destructor for CircularLinkedList
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user