@SuppressWarnings("unchecked")
    public V put(K key, V value) {
        Entry<K, V> t = root;
        if (t == null) {
            root = new Entry<K, V>(key, value, null);
            size = 1;
            return null;
        }
        int cmp;
        Entry<K, V> parent;
        if (key == null)
            throw new NullPointerException();
        Comparable<? super K> k = (Comparable<? super K>) key;
        do {
            parent = t;
            cmp = k.compareTo(t.key);
            if (cmp < 0)
                t = t.left;
            else if (cmp > 0)
                t = t.right;
            else
                return t.value = value;
        } while (t != null);
        Entry<K, V> e = new Entry<K, V>(key, value, parent);
        if (cmp < 0)
            parent.left = e;
        else
            parent.right = e;
        fixAfterInsertion(e);
        size++;
        return null;
    }