mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-01 17:52:40 +08:00
fix: memory leak in morrisinorder.cpp (#2729)
This commit is contained in:
@@ -81,6 +81,14 @@ void morrisInorder(Btree *root) {
|
||||
}
|
||||
}
|
||||
|
||||
void deleteAll(const Btree *const root) {
|
||||
if (root) {
|
||||
deleteAll(root->left);
|
||||
deleteAll(root->right);
|
||||
delete root;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Testing morrisInorder funtion
|
||||
Btree *root = NULL;
|
||||
@@ -88,5 +96,6 @@ int main() {
|
||||
for (i = 1; i <= 7; i++) insert(&root, i);
|
||||
cout << "Morris Inorder: ";
|
||||
morrisInorder(root);
|
||||
deleteAll(root);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user