mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Added destructor for CircularLinkedList
This commit is contained in:
parent
f7d7da69b9
commit
797f1f4327
@ -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";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user