/** @return the next smallest number */ publicintnext(){ if (!iter.isEmpty()){ TreeNode ans=iter.pop(); if (ans.right!=null){ pushStack(ans.right); } return ans.val; } return -1; }
/** @return whether we have a next smallest number */ publicbooleanhasNext(){ return !iter.isEmpty(); } }