Question: 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

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!