Question: I have a question here in java Binary search tree Sorted I have the Node class here And 3 more different methods Class Node public
I have a question here in java
Binary search tree Sorted
I have the Node class here
And 3 more different methods
Class Node
public class Node
{
private int _number;
private Node _leftSon, _rightSon;
public Node (int number)
{
_number = number;
_leftSon = null;
_rightSon = null;
}
public int getNumber() {return _number; }
public Node getLeftSon() {return _leftSon; }
public Node getRightSon() {return _rightSon; }
}
public static Node secret(Node root, int num1, int num2)
//Assuming num1 <= num2
{
if (root == null)
return null;
root.setLeftSon(secret(root.getLeftSon(), num1, num2));
root.setRightSon(secret(root.getRightSon(), num1, num2));
if (root.getNumber() < num1)
root = root.getRightSon();
else if (root.getNumber() > num2)
root = root.getLeftSon();
return root;
}
public static void what(Node root)
{
if (root != null)
{
what(root.getLeftSon());
System.out.print (root.getNumber() + " ");
what(root.getRightSon());
}
}
public static void what2 (Node n, int value)
{
if (n == null)
return;
else
{
n.setNumber( value);
what (n.getLeftSon(), value+1);
what (n.getRightSon(), value+1);
}
}
60
/ \
20 70
/ \
10 38
/ / \
5 25 45
\
30
a. What does the what2 method do?
b. What does the secret method do when it gets as a root parameter of a binary search tree
And two integers num1 <= num2?
c. How to create the tree if we use the secret method With
BinarySearchTree.secret parameters (root, 10, 30)?
e. How will she print a Parrot Order In Order using the what method
In both trees in the previous tree and in the new tree in section c?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
