Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Tree sortedDelete(Tree t, int v){
- Tree cpy = null;
- if(t != null){
- cpy = t.copy();
- if(cpy.value == v){
- if(cpy.right != null && cpy.left != null){
- cpy.value = cpy.right.getMin().value;
- cpy.right = sortedDelete(cpy.right.getMin(), cpy.value);
- }
- if(cpy.right != null && cpy.left == null){
- cpy = cpy.right;
- }
- if(cpy.right == null && cpy.left != null){
- cpy = cpy.left;
- }
- if(cpy.right == null && cpy.left == null){
- cpy = null;
- }
- }else{
- if(t.value < v){
- cpy.right = sortedDelete(t.right, v);
- }else{
- cpy.left = sortedDelete(t.left, v);
- }
- }
- }
- return cpy;
- }
- }
Add Comment
Please, Sign In to add comment