@@ -90,6 +90,20 @@ Node *makeLinkedList(const std::vector<uint64_t> &data) {
90
90
return head;
91
91
}
92
92
93
+ /*
94
+ * @brief This function dealocates memory related to the given list
95
+ * It recursively deletes all of the nodes of the input list.
96
+ * @param room the root/head of the input list
97
+ * @warning Plese note that the memory for each node has to be alocated using
98
+ * new.
99
+ */
100
+ void deleteList (Node *const root) {
101
+ if (root != NULL ) {
102
+ deleteList (root->next );
103
+ delete root;
104
+ }
105
+ }
106
+
93
107
/* *
94
108
* @brief Main searching function
95
109
* @param sublist A linked list which is supposed to be searched in mainList.
@@ -217,8 +231,8 @@ class TestCases {
217
231
log (" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
218
232
" ~" );
219
233
220
- delete (sublistLL );
221
- delete (mainlistLL );
234
+ deleteList (mainlistLL );
235
+ deleteList (sublistLL );
222
236
}
223
237
224
238
/* *
@@ -270,6 +284,9 @@ class TestCases {
270
284
log (" [PASS] : TEST CASE 2 PASS!" );
271
285
log (" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
272
286
" ~" );
287
+
288
+ deleteList (mainlistLL);
289
+ deleteList (sublistLL);
273
290
}
274
291
275
292
/* *
@@ -318,6 +335,9 @@ class TestCases {
318
335
log (" [PASS] : TEST CASE 3 PASS!" );
319
336
log (" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
320
337
" ~" );
338
+
339
+ deleteList (mainlistLL);
340
+ deleteList (sublistLL);
321
341
}
322
342
};
323
343
@@ -366,5 +386,8 @@ int main(int argc, char *argv[]) {
366
386
} else {
367
387
std::cout << " [FALSE] - sublist NOT found in main list\n " ;
368
388
}
389
+
390
+ deleteList (mainlistLL);
391
+ deleteList (sublistLL);
369
392
return 0 ;
370
393
}
0 commit comments