public Entry<Integer, V> next() {
            if (stack.isEmpty())
                throw new NoSuchElementException();

            IntTree<V> node = stack.get(0);
            final Entry<Integer, V> result = new AbstractMap.SimpleImmutableEntry<Integer, V>(key, node.value);

            // find next node.
            // we've already done everything smaller,
            // so try least larger node:

            if (node.right.size > 0) // we can descend to the right
                gotoMinOf(node.right);

            else // can't descend to the right -- try ascending to the right
                while (true) { // find current node's least larger ancestor, if any
                    key -= node.key; // revert to parent's key
                    stack = stack.subList(1); // climb up to parent
                    // if parent was larger than child or there was no parent, we're done:
                    if (node.key < 0 || stack.size() == 0)
                        break;
                    // otherwise parent was smaller -- try its parent:
                    node = stack.get(0);
                }

            return result;
        }