Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

package Lab11; public class BinaryTree { private BinaryTreeNode root; public BinaryTree(){ root=null; } public boolean isEmpty(){ return root==null; } public BinaryTreeNode insert(BinaryTreeNode node, int data)

image text in transcribed

package Lab11;

public class BinaryTree {

private BinaryTreeNode root;

public BinaryTree(){

root=null;

}

public boolean isEmpty(){

return root==null;

}

public BinaryTreeNode insert(BinaryTreeNode node, int data)

{

//Implement the insert method here

}

public void insert(int data){

root=insert(root, data);

}

private int countNodes(BinaryTreeNode r){

if(r==null)

return 0;

else

{

int number=1;

number+=countNodes(r.getLeft());

number+=countNodes(r.getRight());

return number;

}

}

public int countNodes(){

return countNodes(root);

}

public boolean search(BinaryTreeNode r, int data){

if(r.getData()==data)

return true;

if(r.getLeft()!=null)

if(search(r.getLeft(),data))

return true;

if(r.getRight()!=null)

if(search(r.getRight(),data))

return true;

return false;

}

public boolean search(int val){

return search(root, val);

}

private void inorder(BinaryTreeNode r){

if(r!=null){

inorder(r.getLeft());

System.out.println(r.getData()+"");

inorder(r.getRight());

}

}

public void inorder(){

inorder(root);

}

private void preorder(BinaryTreeNode r){

if(r!=null){

System.out.println(r.getData()+"");

preorder(r.getLeft());

preorder(r.getRight());

}

}

public void preorder(){

preorder(root);

}

private void postorder(BinaryTreeNode r){

if(r!=null){

postorder(r.getLeft());

postorder(r.getRight());

System.out.println(r.getData()+"");

}

}

public void postorder(){

postorder(root);

}

}

package Lab11;

public class BinaryTreeNode {

BinaryTreeNode left;

BinaryTreeNode right;

int data;

public BinaryTreeNode(){

left=null;

right=null;

data=0;

}

public BinaryTreeNode(int value){

left=null;

right=null;

data=value;

}

public void setLeft(BinaryTreeNode node){

left=node;

}

public void setRight(BinaryTreeNode node){

right=node;

}

public void setData(int value){

data=value;

}

public BinaryTreeNode getLeft(){

return left;

}

public BinaryTreeNode getRight(){

return right;

}

public int getData(){

return data;

}

}

package Lab11;

import java.util.Scanner;

public class BinaryTreeTest {

public static void main(String[] args){

//produce the sequence here

//insert the data to the binary search tree here

//perform the sorting here.

}

}

whole Java code ,thanks

Sorting A Sequence Using the Binary Search Tree. Instructions: A) Goal: get experience with binary search tree. B) Task: 1) Produce a sequence of 15 random integers, print this sequence preceding with (Points:20/100) Unsorted" In the attached java class named BinarvTree, re-design the insert method to produce a binary search tree. 2) (Points: 60/100) 3) Using the inorder method to sort the sequence, print the sorted sequence (Points: 20/100) c) Procedure: the attached classes 1. download 2. implement the insert method. 3. Run the Test class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions