protected Node erase(K key) { int value = compare(key, this.key); if (value == 0) return merge(left, right); if (value < 0) { left = left.erase(key); updateSize(); return this; } right = right.erase(key); updateSize(); return this; }
public K pollFirst() { K first = first(); if (first == null) throw new NoSuchElementException(); root.erase(first); return first; }
public boolean remove(Object o) { if (!contains(o)) return false; //noinspection unchecked root = root.erase((K) o); return true; }
public K pollLast() { K last = last(); if (last == null) throw new NoSuchElementException(); root.erase(last); return last; }