Simple Iterative solution


#1
int Solution::kthsmallest(TreeNode* A, int B) {
stack<TreeNode*> s;
TreeNode* current = A;
int k = 0;
while(current || !s.empty()){
    while(current){
        s.push(current);
        current = current->left;
    }
    current = s.top();
    s.pop();
    k++;
    if(k == B)
        return current->val;
    current = current->right;
}
return -1;

}