Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private BSTNode removeRootOf(BSTNode subroot){
- if (subroot.left ==null && subroot.right == null)
- return null;
- if(subroot.left == null || subroot.right == null){
- if(subroot.left == null){
- return subroot.right;
- }
- else { return subroot.left;}
- }
- BSTNode rightchild = subroot.right;
- if(rightchild.left == null){
- rightchild.left = subroot.left;
- return rightchild;
- }
- BSTNode parent = rightchild;
- while (parent.left.left != null) {
- parent = parent.left;
- }
- BSTNode leftmostNode = parent.left;
- parent.left = leftmostNode.right;
- leftmostNode.right = rightchild;
- leftmostNode.left = subroot.left;
- return leftmostNode;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement