File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,13 @@ ListNode* middleNode(ListNode* head) {
7373
7474 return (fastptr->next ) ? slowptr->next : slowptr;
7575}
76+
77+ void deleteAll (const ListNode* const head) {
78+ if (head) {
79+ deleteAll (head->next );
80+ delete head;
81+ }
82+ }
7683} // namespace median_search2
7784} // namespace search
7885
@@ -98,6 +105,7 @@ static void test() {
98105
99106 ListNode* median = search::median_search2::middleNode (head1);
100107 assert (3 == median->val ); // 3 is the value of the median node.
108+ search::median_search2::deleteAll (head1);
101109 std::cout << " test case:1 passed\n " ;
102110
103111 // Test case # 2
@@ -118,14 +126,9 @@ static void test() {
118126
119127 ListNode* median1 = search::median_search2::middleNode (head2);
120128 assert (4 == median1->val ); // 4 is the value of the median node.
129+ search::median_search2::deleteAll (head2);
121130 std::cout << " test case:2 passed\n " ;
122131
123- delete head1;
124- delete temp;
125-
126- delete head2;
127- delete temp2;
128-
129132 std::cout << " --All tests passed--\n " ;
130133}
131134
You can’t perform that action at this time.
0 commit comments