Question: Use the following files to write a java program that implements a binary tree. The program should use an array and fill the elements from

Use the following files to write a java program that implements a binary tree. The program should use an array and fill the elements from the array into a tree structure. The program should produce output as shown below when inserting array elements.Use the following files to write a java program that implements a

Tree Class:

public class Tree { @SuppressWarnings("unused") public Tree(int[] array) { Node root = new Node(array[0]); root.setRoot(true); Node current = root; int level = 0; for(int i=1; i

TreeDriver Class:

public class TreeDriver { @SuppressWarnings("unused") private int [] array = {8,3,5,7,1,6,4,9,2,0}; //private int [] array = {1,2,3,4,5,6,7,8,9}; }

Node Class:

public class Node { private int value; private Node left; private Node right; private boolean isRoot=false; public Node(int value) { } public int getValue() {return value;} public void setValue(int value) {this.value = value; } public Node getLeft() {return left;} public void setLeft(Node left) {this.left = left;} public Node getRight() {return right;} public void setRight(Node right) {this.right = right;} public boolean isRoot() {return isRoot;} public void setRoot(boolean isRoot) {this.isRoot = isRoot;} }

D:\Java_Deu\WEB\java2s java BinaryTreeTest Binary Tree Example Building tree with root value 5 Inserted 1 to left of 5 Inserted 8 to right of 5 Inserted 6 to left of 8 Inserted 3 to right of 1 Inserted 9 to right of 8 Traversing tree in order Traversed 1 Traversed 3 Traversed 5 Traversed 6 Traversed 8 Traversed 9 Traversing tree front-to-back from location 7 Traversed 6 D:\Java_Deu\WEB\java2s java BinaryTreeTest Binary Tree Example Building tree with root value 5 Inserted 1 to left of 5 Inserted 8 to right of 5 Inserted 6 to left of 8 Inserted 3 to right of 1 Inserted 9 to right of 8 Traversing tree in order Traversed 1 Traversed 3 Traversed 5 Traversed 6 Traversed 8 Traversed 9 Traversing tree front-to-back from location 7 Traversed 6

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 Databases Questions!