Advertisement
Guest User

Bro

a guest
Mar 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. public boolean delete(T key) {
  2. if (!search(key)) {
  3. return false;
  4. }
  5. Node<T> node = find(root, key);
  6. Node<T> desc = null;
  7. if (node.getRightChild() == null && node.getLeftChild() != null) {
  8. desc = (Node<T>) node.getLeftChild();
  9. } else if (node.getRightChild() != null) {
  10. desc = leftDescendant((Node<T>) node.getRightChild());
  11. }
  12. else{
  13. node = null;
  14. }
  15. if (node != null) {
  16. node.setValue(desc.getValue());
  17. if (desc.getParent() != null) {
  18. ((Node<T>) desc.getParent()).setLeftChild(null);
  19. }
  20. }
  21. balance(node);
  22. return true;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement