Data Structure Binary Tree: Iterative Postorder Traversal
http://www.geeksforgeeks.org/iterative-postorder-traversal-using-stack/
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
using namespace std; struct node {
int data;
struct node *left, *right;
node() : data(), left(NULL), right(NULL) { }
node(int d) : data(d), left(NULL), right(NULL) { }
}; void prints(node *root) {
if (!root) return;
stack<node*> S;
do {
while (root) {
if (root->right) S.push(root->right);
S.push(root);
root = root->left;
}
root = S.top();
S.pop();
if (root->right && !S.empty() && root->right == S.top()) {
S.pop();
S.push(root);
root = root->right;
}
else {
cout << root->data << " ";
root = NULL;
}
} while (!S.empty());
} int main() {
node *root = new node();
root->left = new node();
root->right = new node();
root->left->left = new node();
root->left->right = new node();
root->right->left = new node();
root->right->right = new node();
prints(root);
return ;
}
Data Structure Binary Tree: Iterative Postorder Traversal的更多相关文章
- Data Structure Binary Tree: Level order traversal in spiral form
http://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/ #include <iostream> #includ ...
- Data Structure Binary Tree: Morris traversal for Preorder
http://www.geeksforgeeks.org/morris-traversal-for-preorder/ #include <iostream> #include <v ...
- Data Structure Binary Tree: Construct Full Binary Tree from given preorder and postorder traversals
http://www.geeksforgeeks.org/full-and-complete-binary-tree-from-given-preorder-and-postorder-travers ...
- Data Structure Binary Tree: Boundary Traversal of binary tree
http://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/ #include <iostream> #include & ...
- Data Structure Binary Tree: Inorder Tree Traversal without recursion and without stack!
http://www.geeksforgeeks.org/inorder-tree-traversal-without-recursion-and-without-stack/ #include &l ...
- Data Structure Binary Tree: Inorder Tree Traversal without Recursion
http://www.geeksforgeeks.org/inorder-tree-traversal-without-recursion/ #include <iostream> #in ...
- Data Structure Binary Tree: Lowest Common Ancestor in a Binary Tree
http://www.geeksforgeeks.org/lowest-common-ancestor-binary-tree-set-1/ #include <iostream> #in ...
- Data Structure Binary Tree: Connect nodes at same level using constant extra space
http://www.geeksforgeeks.org/connect-nodes-at-same-level-with-o1-extra-space/ recursive: #include &l ...
- Data Structure Binary Tree: Print ancestors of a given binary tree node without recursion
http://www.geeksforgeeks.org/print-ancestors-of-a-given-binary-tree-node-without-recursion/ #include ...
随机推荐
- Android轻量级日志管理框架
代码地址如下:http://www.demodashi.com/demo/12134.html ViseLog Android 轻量级日志框架,使用森林对象维护不同的日志树进行日志输出,可以是Logc ...
- 【SpringMVC学习09】SpringMVC与前台的json数据交互
json数据格式在接口调用中.html页面中比较常用,json格式比较简单,解析也比较方便,所以使用很普遍.在springmvc中,也支持对json数据的解析和转换,这篇文章主要总结一下springm ...
- Eclipse配色利器
1 http://eclipsecolorthemes.org/ 这是官网 2 安装后,window-preferences-general-appearance-color theme 即可找到多 ...
- ORACLE 12C R2 RAC 安装配置指南
>> from zhuhaiqing.info ASM磁盘空间最低要求 求12C R2相比前一版本,OCR的磁盘占用需求有了明显增长.为了方便操作,设置如下:External: 1个卷x4 ...
- CentOS下使用yum快速安装memcached
1. 查找Memcached yum search memcached 首先检查yum软件仓库中是否存在memcached,如果有 直接进入第3步安装即可,否则执行第2步. 2. 安装第三方软件库(可 ...
- delphi 无边框窗体常见问题
实现无边框窗体很简单,直接将窗体的BorderStyle属性设置为bsNone即可.但是这样会引起2个问题: 1.在xp系统下,任务栏鼠标右键点击无法弹出菜单 解决办法:在FormShow中加入这个过 ...
- gen_server2 与gen_server的对比
在erlang杀手级应用rabbitmq中,不难发现,有一个gen_server2.erl模块.而在rabbitmq中,gen_server2.erl是对gen_server.erl模块的重写. Ra ...
- CyclicBarrier的工作原理及其实例
CyclicBarrier是多线程中一个重要的类,主要用于线程组内部之间的线程的相互等待问题. 1.CyclicBarrier的工作原理 CyclicBarrier大致是可循环利用的屏障,顾名思义,这 ...
- SharePoint 2013的100个新特性 免费电子书下载
简介:这本电子书对SharePoint 2013的100个新特性和改进的功能提供了一个简短的说明,这些功能分为以下几类: 1. SharePoint 2013内容管理 2. SharePoint 20 ...
- 从sql走向linq的我撞死在起点上
[本文纯个人理解,错误轻喷,非常希望能有大神指点] A left (outer) join B on A.bid=B.id 上面这句话叫做左连接,原因是left(左)join(加入,连入)被译为左连接 ...