Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions search/median_search2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ ListNode* middleNode(ListNode* head) {

return (fastptr->next) ? slowptr->next : slowptr;
}

void deleteAll(const ListNode* const head) {
if (head) {
deleteAll(head->next);
delete head;
}
}
} // namespace median_search2
} // namespace search

Expand All @@ -98,6 +105,7 @@ static void test() {

ListNode* median = search::median_search2::middleNode(head1);
assert(3 == median->val); // 3 is the value of the median node.
search::median_search2::deleteAll(head1);
std::cout << "test case:1 passed\n";

// Test case # 2
Expand All @@ -118,14 +126,9 @@ static void test() {

ListNode* median1 = search::median_search2::middleNode(head2);
assert(4 == median1->val); // 4 is the value of the median node.
search::median_search2::deleteAll(head2);
std::cout << "test case:2 passed\n";

delete head1;
delete temp;

delete head2;
delete temp2;

std::cout << "--All tests passed--\n";
}

Expand Down
Loading