```
class Solution(object):
def kthSmallest(self, root, k):
"""
:type root: TreeNode
:type k: int
:rtype: int
"""
stack = [(root, False)]
count = 0
while stack:
node, flag = stack.pop()
if node:
if flag:
count += 1
if count == k: return node.val
else:
stack.append((node.right, False))
stack.append((node, True))
stack.append((node.left, False))
```

`(node, flag)`

tuple represents the node to visit and whether the node has been visited, and for in-order we go left child first then node then right child.