/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution
{
public:
vector<int> inorderTraversal(TreeNode *root)
{
stack<TreeNode *> s;
vector<int> v;
if (root == nullptr)
return v;
TreeNode *cur = root;
s.push(root);
while (cur->left != nullptr)
{
cur = cur->left;
s.push(cur);
}
while (!s.empty())
{
cur=s.top();
s.pop();
v.push_back(cur->val);
if (cur->right != nullptr)
{
cur = cur->right;
s.push(cur);
while (cur->left != nullptr)
{
cur = cur->left;
s.push(cur);
}
}
}
return v;
}
};
10-11
1819
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-30
3302
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-09
587
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-08
1354
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)