Question: Note that code should must be in java and we are only allow to make changes in BSTChecker.java but not LabProgram.java and Node.java please make
Note that code should must be in java and we are only allow to make changes in BSTChecker.java but not LabProgram.java and Node.java please make sure to write the full code of BSTChecker.java
the given code is as follow:
import java.util.;
public class Node
private static String removeLeadingWhitespaceString str
int i ;
while i int strlength
If the character at index i is not whitespace, then return the
substring that starts at i
if Character.isWhitespacestrcharAti
return strsubstringi;
i;
Completing the loop means the entire string is whitespace
return new String;
public int key;
public Node left;
public Node right;
public Nodeint nodeKey, Node leftChild
thisnodeKey leftChild, null;
public Nodeint nodeKey
thisnodeKey null, null;
public Nodeint nodeKey, Node leftChild, Node rightChild
key nodeKey;
left leftChild;
right rightChild;
public void close
Counts the number of nodes in this tree
public int count
int leftCount ;
if left null
leftCount left.count;
int rightCount ;
if right null
rightCount right.count;
return leftCount rightCount;
Inserts the new node into the tree.
public void insertNode node
Node currentNode this;
while currentNode null
if nodekey currentNode.key
if currentNodeleft null
currentNode currentNode.left;
else
currentNode.left node;
currentNode null;
else
if currentNoderight null
currentNode currentNode.right;
else
currentNode.right node;
currentNode null;
public void insertAllfinal ArrayList keys
for int key : keys
insertnew Nodekey;
public static Node parseString treeString
A node is enclosed in parentheses with a either just a key: key
or a key, left child, and right child triplet: key left, right The
left and right children, if present, can be either a nested node or
"null".
Remove leading whitespace first
treeString Node.removeLeadingWhitespacetreeString;
The string must be nonempty, start with and end with
if treeString.length treeString.charAt
treeString.charAttreeStringlength
return null;
Parse between parentheses
treeString treeString.substring treeString.length;
Find nonnested commas
ArrayList commaIndices new ArrayList;
int parenCounter ;
for int i ; i int treeString.length; i
char character treeString.charAti;
if character
parenCounter;
else if character
parenCounter;
else if character && parenCounter
commaIndices.addi;
If no commas, treeString is expected to be just the node's key
if commaIndices.size
return new NodeIntegerparseInttreeString;
If number of commas is not then the string's format is invalid
if commaIndices.size
return null;
"Split" on comma
int i commaIndices.get;
int i commaIndices.get;
String piece treeString.substring i;
String piece treeString.substringi i;
String piece treeString.substringi;
Make the node with just the key
Node nodeToReturn new NodeIntegerparseIntpiece;
Recursively parse children
nodeToReturn.left Node.parsepiece;
nodeToReturn.right Node.parsepiece;
return nodeToReturn;
import java.util.;
public class LabProgram
public static void mainString args
Get user input
Scanner reader new ScannerSystemin;
String userInput reader.nextLine;
Parse into a binary tree
Node userRoot Node.parseuserInput;
if userRoot null
Node badNode BSTChecker.checkBSTValidityuserRoot;
if badNode null
System.out.printStringvalueOfbadNodekey;
System.out.print
;
else
System.out.printNo violation";
System.out.print
;
else
System.out.printFailed to parse input tree";
System.out.print
;
reader.close;
Here, is the BSTChecker.java plase fill out this code
public class BSTChecker
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
