Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean delete(T key) {
- if (!search(key)) {
- return false;
- }
- Node<T> node = find(root, key);
- Node<T> desc = null;
- if (node.getRightChild() == null && node.getLeftChild() != null) {
- desc = (Node<T>) node.getLeftChild();
- } else if (node.getRightChild() != null) {
- desc = leftDescendant((Node<T>) node.getRightChild());
- }
- else{
- node = null;
- }
- if (node != null) {
- node.setValue(desc.getValue());
- if (desc.getParent() != null) {
- ((Node<T>) desc.getParent()).setLeftChild(null);
- }
- }
- balance(node);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement