码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode_94题——Binary Tree Inorder Traversal (二叉树,递归,队列queue,)

时间:2015-04-17 21:47:10      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:

先采用比较简单的递归的方法来做

#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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!