标签:
先采用比较简单的递归的方法来做
#include<iostream>
#include<vector>
using namespace std;
struct TreeNode
{
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
//比较简单的递归的方法来做
/*采用递归的方法进行中序遍历,的方法比较简单,不多说了
*/
void inorder_search(TreeNode* root,vector<int>& temp)
{
if(root->left!=NULL)
inorder_search(root->left,temp);
temp.push_back(root->val);
if(root->right!=NULL)
inorder_search(root->right,temp);
return;
}
vector<int> inorderTraversal(TreeNode *root) {
vector<int> last_result;
if(root==NULL)
return last_result;
inorder_search(root,last_result);
return last_result;
}
int main()
{
}
leetcode_94题——Binary Tree Inorder Traversal (二叉树,递归,队列queue,)
标签:
原文地址:http://www.cnblogs.com/yanliang12138/p/4435971.html