Guest User

Untitled

a guest
Apr 22nd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. public static Tree sortedDelete(Tree t, int v){
  2. Tree cpy = null;
  3. if(t != null){
  4. cpy = t.copy();
  5. if(cpy.value == v){
  6. if(cpy.right != null && cpy.left != null){
  7. cpy.value = cpy.right.getMin().value;
  8. cpy.right = sortedDelete(cpy.right.getMin(), cpy.value);
  9. }
  10.  
  11. if(cpy.right != null && cpy.left == null){
  12. cpy = cpy.right;
  13. }
  14.  
  15. if(cpy.right == null && cpy.left != null){
  16. cpy = cpy.left;
  17. }
  18.  
  19. if(cpy.right == null && cpy.left == null){
  20. cpy = null;
  21. }
  22. }else{
  23. if(t.value < v){
  24. cpy.right = sortedDelete(t.right, v);
  25. }else{
  26. cpy.left = sortedDelete(t.left, v);
  27. }
  28. }
  29. }
  30. return cpy;
  31. }
  32. }
Add Comment
Please, Sign In to add comment