# 【LeetCode】94. 二叉树的中序遍历 结题报告 (C++)

1
\
2
/
3

``````/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<int> inorderTraversal(TreeNode* root) {
vector<int> res;
if(!root)
return res;
vector<int> l = inorderTraversal(root->left);
res.insert(res.end(), l.begin(), l.end());
res.push_back(root->val);
vector<int> r = inorderTraversal(root->right);
res.insert(res.end(), r.begin(), r.end());
return res;
}
};``````

``````/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<int> inorderTraversal(TreeNode* root) {
stack<TreeNode*> stack1;
vector<int> order;
TreeNode *pur=root;
while (!stack1.empty()||pur){
while (pur!=NULL){
stack1.push(pur);
pur=pur->left;
}
TreeNode* top=stack1.top();
if(top->right!=NULL){
pur=top->right;
}
order.push_back(top->val);
stack1.pop();
}
return order;
}
};``````

;