Question: Create a Java program that can visually display the structure of a BST . Your program should clearly show the hierarchical relationships between nodes and

Create a Java program that can visually display the structure of a BST. Your program should clearly show the hierarchical relationships between nodes and the overall structure of the tree.
Requirements:
Tree Node Implementation:
Implement a TreeNode class representing the nodes of the BST. Each node should have integer data, a left child, and a right child.
BST Construction:
Using the code in class to construct a BST with sample data. Ensure your tree has at least three levels for testing purposes.
Visual Display Function:
Write a function in Java, printTree(), that visually prints the BST. The output should clearly display the hierarchical structure of the tree, including each level of the tree and the parent-child relationships. The tree should be printed with the root at the top, branching down to its children, and so forth. Use appropriate spacing, and characters like / and \ to indicate branches, or using different number of --- to indicate different levels.
Example Output:
Your program should produce an output similar to the following structure for a sample tree:
Example output one (2% bonus towards final grade if accomplished with this format):
1
/\
23
/\/\
4567
Example output two:
---1
------2
---------4
---------5
------3
---------6
---------7

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!