public class BSTIterator<E> {

	Stack<BNode<E>> stack;
 
	public BSTIterator(BNode<E> root) {
	
		stack = new Stack<BNode<E>>();

		while (root != null) {
			stack.push(root);
			root = root.left;
		}
	}
 
	public boolean hasNext() {
		return !stack.isEmpty();
	}
 
	public E next() {
	
		BNode<E> node = stack.pop();
		BNode<E> child = node.right;

        while (child != null) {
            stack.push(child);
            child = child.left;
        }

		return node.item;
	}
}