Created
February 18, 2022 19:14
-
-
Save maxgoren/2e1ed60afed9354c2889306d3fe27118 to your computer and use it in GitHub Desktop.
delete arbitrary nodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Node<K,V> delete(Node<K,V> h, K key) | |
{ | |
if (h == null) | |
return null; | |
if (key.compareTo(h.key()) < 0) | |
h.setLeft(delete(h.leftChild(), key)); | |
else if (key.compareTo(h.key()) > 0) | |
h.setRight(delete(h.rightChild(), key)); | |
else { | |
if (h.rightChild() == null) | |
return h.leftChild(); | |
Node<K,V> temp = h; | |
h = min(temp.rightChild()); | |
h.setRight(deleteMin(temp.rightChild())); | |
h.setLeft(temp.leftChild()); | |
} | |
return h; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment