Question: There are N numbers in the sequence. Please insert those numbers into the empty Binary Search Tree one by one. After the Binary Search Tree
There are N numbers in the sequence.
Please insert those numbers into the empty Binary Search Tree one by one.
After the Binary Search Tree has been constructed:
(1) Print out the tree with pre-order traversal, in-order traversal and post-order traversal.
(2) Try to delete the number provided from the tree, and then print out the tree with tree different methods of traversal described above.
IMPUT:
N
The sequence of numbers
Number which will be deleted from the tree
OUTPUT:
The sequence of the tree by pre-order traversal
The sequence of the tree by in-order traversal
The sequence of the tree by post-order traversal
NEW TREE AFTER DELETING number
The sequence of the tree by pre-order traversal
The sequence of the tree by in-order traversal
The sequence of the tree by post-order traversal
SAMPLE INPUT:
8 3 1 4 6 9 2 5 7 4
SAMPLE OUTPUT:
PRE_ORDER:3 1 2 4 6 5 9 7 IN_ORDER:1 2 3 4 5 6 7 9 POST_ORDER:2 1 5 7 9 6 4 3 DESCENDING_ORDER:9 7 6 5 4 3 2 1 NEW TREE AFTER DELETING 4 PRE_ORDER:3 1 2 6 5 9 7 IN_ORDER:1 2 3 5 6 7 9 POST_ORDER:2 1 5 7 9 6 3 DESCENDING_ORDER:9 7 6 5 3 2 1
SOURCE:
C++
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
