```
class Solution {
public:
vector<int> inorderTraversal(TreeNode* root) {
TreeNode *current,*p;
vector<int> k1;
if(root==NULL)
return k1;;
current=root;
while(current!=NULL){
if(current->left==NULL){
k1.push_back(current->val);
// cout<<current->val<<" ";
current=current->right;
}
else{
p=current->left;
while(p->right!=NULL && p->right!=current){
p=p->right;
}
if(p->right==current){
k1.push_back(current->val);
// cout<<current->val<<" ";
p->right==NULL;
current=current->right;
}
else{
p->right=current;
current=current->left;
}
}
}
// cout<<"returned";
return k1;
}
};
```