Populate a binary search tree from an input file (input.txt) that contains a list of numbers. The file can also contain the keyword delete followed by a number. Search for a node within the tree for that number and delete it. If the number is not found, insert the node. The tree will not contain any duplicates.
Sample input.txt file
1
2
3
delete 3
5
6
delete 9
Note:
delete 8
8
The above lines will not be in the file because delete 8 will insert a new node since it doesn’t exist and then, the 8 on the next line will attempt to insert a second 8, which would be a duplicate.
At the end, display the tree in preorder, inorder, and postOrder format. Also, display the tree level by level (breadth search format). The display should be redirected to a file (output.txt).
Note: When deleting, make sure to account for no children, one child and two children.
This assignment has been answered 3 times in private sessions.
© 2024 Codify Tutor. All rights reserved