Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.util.*; public class PoD { //============================================================================= /** * Tries to find an object within the binary tree and * returns true if found and
import java.util.*; public class PoD { //============================================================================= /** * Tries to find an object within the binary tree and * returns true if found and false if not * * @param obj Comparable to search for in tree * @param tree BinaryTree of interest * @return boolean value true if object is found, false if not */ public static boolean findValue(Comparable value, BinaryTree tree) { } //============================================================================= public static void main(String[] args) { Scanner in = new Scanner(System.in); Comparable value = in.next(); BinaryTree newTree = buildTree(in); boolean foundItem = findValue(value, newTree); if (foundItem) { System.out.println("Found " + value); } else { System.out.println("Could not find " + value); } in.close(); System.out.print("END OF OUTPUT"); } public static BinaryTree buildTree(Scanner in) { String data = in.next(); BinaryTree left = null; BinaryTree right = null; if (data.equals("null")) { return null;} if (!in.next().equals("(")) { System.out.println("BAD INPUT: (L"); } left = buildTree(in); right = buildTree(in); if (!in.next().equals(")")) { System.out.println("BAD INPUT: R)"); } return new BinaryTree(data, left, right); } }Today you are going to search through a binary search tree to find out if it contains a specified value Details Download the ZIP files named FilesNeeded.zip for use in IntelliJ. When you are happy with your solution, upload the files into the src folder and run. You are going to finish off PoD.java to finish the findValue method Input The main method (already completed) creates a binary tree and passes a Comparable object to search for and the binary tree to search to the method findValue. Processing You are going to complete the details of findValue method. Details of each method and their expected parameters are described in the Javadoc comments preceding it. The method should return true if the value is found within the binary tree, and return false if not. Output Output will be handled by the main method based on the value you return. Examples Sample binary tree (created from samplelnput.in)
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