diff --git a/operations_on_datastructures/circular_linked_list.cpp b/operations_on_datastructures/circular_linked_list.cpp index e1a324427..dd6c46523 100644 --- a/operations_on_datastructures/circular_linked_list.cpp +++ b/operations_on_datastructures/circular_linked_list.cpp @@ -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"; }