Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q)Implementing a Binary Search Tree? Plese do this qustion using JAVA langue I provied to you starter code to print and add code so do

Q)Implementing a Binary Search Tree? Plese do this qustion using JAVA langue I provied to you starter code to print and add code so do it and make it print and Add and search .

*BSTTester.java

public class BSTTester { /** * @param args */ public static void main(String[] args) { BinarySearchTree root = new BinarySearchTree(); root.Add("c"); root.Add("b"); root.Add("a"); root.Add("A"); root.Print(); System.out.println(root.Search("c")); System.out.println(root.Search("d")); } } *BinarySearchTree.java 
public class BinarySearchTree { private T Item; private BinarySearchTree rightChild; private BinarySearchTree leftChild; public void Add(T t) { if(this.Item==null) this.Item=t; else if(t.compareTo(this.Item) < 0) { if(this.leftChild==null) this.leftChild = new BinarySearchTree(); this.leftChild.Add(t); } else { if(this.rightChild==null) this.rightChild = new BinarySearchTree(); this.rightChild.Add(t); } } public void Print() { if(this.leftChild!=null) leftChild.Print(); System.out.println(this.Item); if(this.rightChild!=null) rightChild.Print(); } public boolean Search(T t) { boolean found = false; if(this.Item.equals(t)) found=true; else if(this.rightChild!=null && this.rightChild.Search(t)) found=true; else if(this.leftChild!=null && this.leftChild.Search(t)) found=true; return found; } } 

Q)Implementing a Binary Search Tree? Plese do this qustion using JAVA langue I provied to you starter code to print and add code so do it and make it print and Add and search .

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions

Question

2. Do you find change a. invigorating? b. stressful? _______

Answered: 1 week ago