Skip to content

Commit

Permalink
fix: memory leak in morrisinorder.cpp (#2729)
Browse files Browse the repository at this point in the history
  • Loading branch information
vil02 committed Sep 11, 2024
1 parent d74f4d3 commit 7828b8e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions data_structures/morrisinorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,21 @@ 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;
int i;
for (i = 1; i <= 7; i++) insert(&root, i);
cout << "Morris Inorder: ";
morrisInorder(root);
deleteAll(root);
return 0;
}

0 comments on commit 7828b8e

Please sign in to comment.