Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Definition for a binary tree node.
- * public class TreeNode {
- * int val;
- * TreeNode left;
- * TreeNode right;
- * TreeNode(int x) { val = x; }
- * }
- */
- class BSTIterator {
- private Stack<TreeNode> path;
- private Stack<Character> operations;
- public BSTIterator(TreeNode root) {
- path = new Stack<TreeNode>();
- operations = new Stack<Character>();
- path.push(root);
- operations.push('L');
- }
- /** @return the next smallest number */
- public int next() {
- char operation = operations.peek();
- switch (operation) {
- case 'L':
- TreeNode left = path.peek().left;
- if (left != null) {
- path.push(left);
- operations.push('L');
- }
- break;
- case 'M':
- break;
- case 'R':
- break;
- }
- return 0;
- }
- /** @return whether we have a next smallest number */
- public boolean hasNext() {
- return false;
- }
- }
- /**
- * Your BSTIterator object will be instantiated and called as such:
- * BSTIterator obj = new BSTIterator(root);
- * int param_1 = obj.next();
- * boolean param_2 = obj.hasNext();
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement