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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!