@@ -0,0 +1,958 @@
+/**%0A * Definition for binary tree%0A * public class TreeNode %7B%0A *     int val;%0A *     TreeNode left;%0A *     TreeNode right;%0A *     TreeNode(int x) %7B val = x; %7D%0A * %7D%0A */%0A%0Apublic class BSTIterator %7B%0A    private Deque%3CTreeNode%3E stack;%0A%0A    public BSTIterator(TreeNode root) %7B%0A        stack = new ArrayDeque%3C%3E();%0A        while (root != null) %7B%0A            stack.push(root);%0A            root = root.left;%0A        %7D%0A    %7D%0A%0A    /** @return whether we have a next smallest number */%0A    public boolean hasNext() %7B%0A        return !stack.isEmpty();%0A    %7D%0A%0A    /** @return the next smallest number */%0A    public int next() %7B%0A        TreeNode node = stack.pop();%0A        TreeNode root = node.right;%0A        while (root != null) %7B%0A            stack.push(root);%0A            root = root.left;%0A        %7D%0A        return node.val;%0A    %7D%0A%7D%0A%0A/**%0A * Your BSTIterator will be called like this:%0A * BSTIterator i = new BSTIterator(root);%0A * while (i.hasNext()) v%5Bf()%5D = i.next();%0A */%0A

173. Binary Search Tree Iterator