public TreeNodeWithParent next(){
        if(!hasNext()) throw new NoSuchElementException();
        TreeNodeWithParent r = next;
        // if you can walk right, walk right, then fully left.
        // otherwise, walk up until you come from left.
        if(next.right != null){
            next = next.right;
            while (next.left != null)
                next = next.left;
        }else {
            while(true) {
                if (next.parent == null) {
                    next = null;
                    return r;
                }
                if (next.parent.left == next) {
                    next = next.parent;
                    return r;
                }
                next = next.parent;
            }
        }
        return null;
    }