Using deque and recursion in C++, Short and clean


#1
  void inorder(TreeNode* A, int b, deque<TreeNode* > &dq)
 {
 if(A==NULL) return;
 
 inorder(A->left,b,dq);
 if(dq.size()<b) dq.push_back(A);
 
 if(dq.size()==b) return;
 else inorder(A->right,b,dq);
 
 }
 
 
int Solution::kthsmallest(TreeNode* A, int B) {
deque<TreeNode* > dq;
inorder(A,B,dq);
return dq.back()->val;

}