Question
void insert(String key) { root = insertRec(root, key); } /* A recursive function to insert a new key in BST */ TreeNode insertRec(TreeNode root, String
void insert(String key) {
root = insertRec(root, key);
}
/* A recursive function to insert a new key in BST */
TreeNode insertRec(TreeNode root, String key) {
/* If the tree is empty, return a new TreeNode */
if (root == null) {
root = new TreeNode(key);
return root;
}
/* Otherwise, recur down the tree */
if (key.compareToIgnoreCase(root.key) < 0)
root.leftChild = insertRec(root.leftChild, key);
else if (key.compareToIgnoreCase(root.key) > 0)
root.rightChild = insertRec(root.rightChild, key);
/* return the (unchanged) TreeNode pointer */
return root;
}
I have made this insert method for Binary Search Tree.
Now I need to make methods for delete and retrieve an item in the Binary Search Tree.
Can I get a java code for this? Thanks
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