Iterative in-order traversal using stack (Java solution)
As a lot of us know, this question can be solved by in-order traversal. Here, I am going to show how you can solve this question easily by performing iterative 
As a lot of us know, this question can be solved by in-order traversal. Here, I am going to show how you can solve this question easily by performing iterative in-order traversal using stack.\n\nCode below is the iterative inorder traversal solution. It is pretty straightforward though, so I am not going to explain the code.\n\n    public List<Integer> inorderTraversal(TreeNode root) {\n        List<Integer> list = new ArrayList<>();\n        if(root == null) return list;\n        Stack<TreeNode> stack = new Stack<>();\n        while(root != null || !stack.empty()){\n            while(root != null){\n                stack.push(root);\n                root = root.left;\n            }\n            root = stack.pop();\n            list.add(root.val);\n            root = root.right;\n            \n        }\n        return list;\n    }\n\nHere, we can solve the finding kth smallest element with as little tweak as possible. \n\n     public int kthSmallest(TreeNode root, int k) {\n         Stack<TreeNode> stack = new Stack<>();\n         while(root != null || !stack.isEmpty()) {\n             while(root != null) {\n                 stack.push(root);    \n                 root = root.left;   \n             } \n             root = stack.pop();\n             if(--k == 0) break;\n             root = root.right;\n         }\n         return root.val;\n     }
['Stack', 'Java']