```
int kthSmallest(TreeNode* root, int k) {
stack<TreeNode *> stck;
while (root || !stck.empty()) {
while (root) {
stck.push(root);
root = root->left;
}
root = stck.top();
stck.pop();
if (--k == 0) return root->val;
root = root->right;
}
return 0;
}
```