Simple solution in C++ using a calc function


#1

void calc(stack<TreeNode*>&st,TreeNode* pol)
{
while(pol)
{
st.push(pol);
pol=pol->left;
}
}
vector Solution::inorderTraversal(TreeNode* A) {

stack<TreeNode*>st;
TreeNode* temp=A;

 vector<int>res;
 
   calc(st,temp);  
 
 
 while(!st.empty())
 {
    TreeNode* ptr=st.top();
    res.push_back(ptr->val);
    st.pop();
    if(ptr->right)
    {
        calc(st,ptr->right);
    }
     
 }
 return res;

}