Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need a running java code with comments public class BinaryTreeTest { public static void main(String[] args) { Node root, left, right; left = insertLR(new

I need a running java code with comments

public class BinaryTreeTest { public static void main(String[] args) { Node root, left, right; left = insertLR(new Node(5), new Node(8), new Node(3)); right = insertLR(new Node(11), new Node(82), new Node(35)); root = insertLR(new Node(840), left, right); BinaryTree b = new BinaryTree(root); } public static Node insertLR(Node root, Node left, Node right) { root.left = left; root.right = right; return root; } } 

///////////////////////////////////////////////

class BinaryTree { ... public boolean search( int value ) { // Your code here! } } 

//////////////////////////////////////////

class BinaryTree { Node head; public BinaryTree() { this.head = new Node(0); } public BinaryTree(Node root) { this.head = root; } } class Node { int data; Node left; Node right; public Node(int data) { this(data,null,null); } public Node(int data, Node left, Node right) { this.data = data; this.left = left; this.right = right; } } 

image text in transcribed

image text in transcribed

Option 1: Searching a Binary Tree Option 1 is to implement a method that will search for a value in the given binary tree. Implement a recursive method called search in the Binary Tree class. Your method should take an integer parameter, which is the value it is trying to find in the binary tree. Your method should return a boolean, which is true if there is any Node in the binary tree with data equal to that value, and false otherwise. You should method should be added to the BinaryTree class (see above) Here is the method header for the binary tree search to get you started: class Binary Tree public boolean search int value 1 Your code here

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

Data Management Databases And Organizations

Authors: Watson Watson

5th Edition

0471715360, 978-0471715368

More Books

Students also viewed these Databases questions

Question

=+ How would you advise those problems be resolved?

Answered: 1 week ago