Binary Tree Inorder Traversal
2015-09-08 15:05
274 查看
Given a binary tree, return the inorder traversal of its nodes’ values.
For example: Given binary tree {1,#,2,3},
1
\
2
/
3
return [1,3,2].
Note: Recursive solution is trivial, could you do it iteratively?
题意:中序遍历
For example: Given binary tree {1,#,2,3},
1
\
2
/
3
return [1,3,2].
Note: Recursive solution is trivial, could you do it iteratively?
题意:中序遍历
vector<int> InOrderTraversal(TreeNode *root) { vector<int> path; stack<TreeNode*> stk; while(root != NULL || !stk.empty()) { while(root != NULL) { stk.push(root); root = root->left; } if( !stk.empty()) { root = stk.top(); stk.pop(); root = root->right; } } return path; }
相关文章推荐
- Xcode - ld: library not found for -lPods -******* 错误
- 《开源框架那点事儿34》:Tiny模板语言(VelocityPlus)初步入门
- Nginx技术手册
- 微信公众帐号开发教程第1篇-引言
- 陕西方言学习
- Android开发学习笔记:数据存取之SQLite浅析
- 【leetcode】 Permutations 一个简单next_permutation的实现
- 把字符串转换成整数
- 如何让 IIS Express 支持其他机器访问
- WireShark查看指定的PC应用的网络包
- java中的重载、重写和隐藏
- VS2015编译连接mongodb(mongodb C++ driver)
- spring_150804_controller
- Linux之性能调优--CPU_内存_IO_网络
- C语言中int的取值范围是怎么算出来的
- Binary Tree Preorder Traversal
- openssl - X509证书操作函数
- 漫谈C指针第十四讲---一个指针应用实例
- IOExceptionjava.net.UnknownHostException: api.weix
- ASMCMD fails to start on module libnnz10.so, permission denied