标签:二叉树
先是中序遍历
/** * Definition for binary tree * 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>v; stack<TreeNode*>s; TreeNode* p = root; while(!s.empty() || p != NULL){ if(p != NULL){ s.push(p); p = p->left; }else { p = s.top(); s.pop(); v.push_back(p->val); p = p->right; } } return v; } };
标签:二叉树
原文地址:http://blog.csdn.net/sina012345/article/details/42979843