```
class Solution {
int ans;
int count = 0;
public:
int kthSmallest(TreeNode* root, int k) {
kth(root, k);
return ans;
}
void kth(TreeNode* root, int k){
if(count > k) return;
if(root->left) kth(root->left, k);
count++;
if(count > k) return;
if(count == k) {
ans = root->val;
return;
}
if(root->right) kth(root->right,k);
}
};
```

An implementation of DFS. It will print out the answer when the counter reaches k.