Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Private delete() method */
- private Node<Key, Value> delete(Node<Key, Value> x, Key key) {
- if (x == null) { // 2
- return null; // 2
- }
- int cmp = key.compareTo(x.key); // 3
- if (cmp < 0) { // 4
- x.left = delete(x.left, key); // 4
- } else if (cmp > 0) { // 5
- x.right = delete(x.right, key); // 5
- } else { // 6
- if (x.right == null) { // 6
- return x.left; // 6
- }
- if (x.left == null) { // 7
- return x.right; // 7
- }
- Node<Key, Value> t = x; // 8
- x = findMin(t.right); // 8
- x.right = deleteMin(t.right); // 8
- x.left = t.left; // 8
- }
- x.size = 1 + size(x.left) + size(x.right); // 9
- return x; // 10
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement