Advertisement
Guest User

delete

a guest
May 25th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. TREE-DELETE(T,n)
  2. if war = True
  3. z = TREE-SUCCESSOR(n)
  4. else
  5. z = TREE-PREDECESSOR(n)
  6.  
  7. // case 1 z jest liściem
  8. // case 2 z ma jedno dziecko
  9. // case 3 z ma dwoje dzieci
  10.  
  11. if z.left = NIL OR z.right = NIL
  12. y = z //case 1 2
  13. else
  14. y = TREE-SUCCESSOR(z) //case 3
  15. if y.left ≠ NIL
  16. x = y.left
  17. else
  18. x = y.right
  19. if x ≠ NIL
  20. x.p = y.p //case 2 3
  21. if y.p = NIL
  22. T.root = x
  23. else
  24. if y = y.p.left
  25. y.p.left = x
  26. else
  27. y.p.right = x
  28. if y ≠ z //case 3
  29. z.key = y.key
  30.  
  31. delete y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement