Binary Tree Inorder Traversal 二叉树的中序遍历
来源:互联网 发布:select2.js 中文api 编辑:程序博客网 时间:2024/05/18 00:19
/**
* 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> vec;
stack<TreeNode*> s;
TreeNode *p=root;
while(p!=NULL||!s.empty())
{
while(p!=NULL)
{
s.push(p);
p=p->left;
}
if(!s.empty())
{
p=s.top();
s.pop();
vec.push_back(p->val);
p=p->right;
}
}
return vec;
}
};
* 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> vec;
stack<TreeNode*> s;
TreeNode *p=root;
while(p!=NULL||!s.empty())
{
while(p!=NULL)
{
s.push(p);
p=p->left;
}
if(!s.empty())
{
p=s.top();
s.pop();
vec.push_back(p->val);
p=p->right;
}
}
return vec;
}
};
0 0
- Binary Tree Inorder Traversal 二叉树的中序遍历
- 二叉树的中序遍历 Binary Tree Inorder Traversal
- Binary Tree Inorder Traversal 二叉树的中序遍历
- LeetCode Binary Tree Inorder Traversal 中序遍历二叉树
- 94.LeetCode Binary Tree Inorder Traversal(medium)[中序遍历二叉树 树的遍历]
- Binary Tree Inorder Traversal——二叉树的中序遍历
- LeetCode | Binary Tree Inorder Traversal(二叉树的中序遍历)
- LeetCode—***Binary Tree Inorder Traversal二叉树的中序遍历
- LeetCode OJ 之 Binary Tree Inorder Traversal (二叉树的中序遍历)
- LintCode Binary Tree Inorder Traversal 二叉树的中序遍历(非递归)
- LeetCode 94. Binary Tree Inorder Traversal(二叉树的中序遍历)
- Binary Tree Inorder Traversal 二叉树的中序遍历(迭代非递归版本)
- 67.Binary Tree Inorder Traversal-二叉树的中序遍历(容易题)
- [LeetCode]94. Binary Tree Inorder Traversal--二叉树的中序遍历
- 【LeetCode】Binary Tree Inorder Traversal二叉树的中序遍历
- LeetCode 94 Binary Tree Inorder Traversal(二叉树的中序遍历)+(二叉树、迭代)
- Construct Binary Tree from Inorder and Postorder Traversal 中序和后序遍历二叉树
- Binary Tree Inorder Traversal 中序遍历二叉树 递归和非递归版
- 【iOS开发】---- 语音识别
- Cocos2d-x 触屏事件解析
- 在Ubuntu中搭建Qt Creator对BBB的交叉编译环境
- UML——活动图
- 深入剖析三层交换机的工作过程
- Binary Tree Inorder Traversal 二叉树的中序遍历
- Android设计模式系列(0)--Android源码中所使用到的设计模式design patterns
- Spring Aop 动态代理
- [Android]调用另一个布局xml文件里面的button,并绑定OnClickListener监听器
- [转载]CString、TCHAR*、char*转换
- java中final关键字的编译问题
- NoSQL研究及选型报告
- 二维数组画图
- Unique Binary Search Trees II