Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(30 pts) A binary search tree is given, write a method to delete a node from the tree. Assume the successor and predecessor methods
(30 pts) A binary search tree is given, write a method to delete a node from the tree. Assume the successor and predecessor methods are provided, partial code is provided below. Finish the reset of the code in the blanks. public Blade deleteNode( BNode coat Comparable e) { if(root == null) return root; if (coat.getData().compareTo((Integer) e) > 0) { //move left caat left = }else if(caat getData().compareTo((Integer) e) < 0) { //move right Cat.cight = deleteNode(coetudeft, e); deleteNode(coat.right, e); if(castleft == null && coat tight == null){ //its a leaf else{ //oh yes, we finally found the target node; easy peasy else if(coot right != null){ // oh, it has a right child, don't make it an orphan or is it old enough to become a parent ? lets find out }else{ //oh it seems that I do not have a worthy successor, fallback, fallback } } } return root; private int successor (Bode, root) { root caturight; while(root left != null) { } } root = coat left; return (Integer) root getData(); private int predecessor (BNode root) { } root = coat left; while(coat cight != null) { root castights return (Integer) coat.getData(); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Program public BNode deleteNodeBNode root Comparable Integer e if root null return root if rootgetDa...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