Question
1. Printing the elements in a binary tree ordered by depth. The root has depth 0, the roots children have depth one, and so on.
1. Printing the elements in a binary tree ordered by depth. The root has depth 0, the roots children have depth one, and so on.
For example, for the tree in the figure, your program should output:
Keys at depth 0: 10
Keys at depth 1: 4 15
Keys at depth 2: 2 8 12 18
Keys at depth 3: 1 3 5 9
Keys at depth 4: 7
bstNode.java
public class bstNode{ public int item; public bstNode left; public bstNode right; public bstNode(int i){ item = i; left = null; right = null; } public bstNode(int i, bstNode l, bstNode r){ item = i; left = l; right = r; } }
bst_ops.java
import java.util.Scanner; public class bst_ops{ public static bstNode insert(bstNode T, int i){ if (T==null) T = new bstNode(i); else if (i
bstNode B=null; for (int i=0;i B = delete(B,18); pause(); draw_tree(B, 0, x_max, y_max-5, (y_max-10.0)/height(B)); B = delete(B,5); pause(); draw_tree(B, 0, x_max, y_max-5, (y_max-10.0)/height(B)); B = delete(B,10); pause(); draw_tree(B, 0, x_max, y_max-5, (y_max-10.0)/height(B)); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started