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 ...
随机推荐
- Gradle学习小结
build.gradle(依赖配置) // 普通java工程 apply plugin: 'java' // Idea工程 apply plugin: 'idea' // war工程,需要有webap ...
- js获取时间查并实现倒计时读条
<script type="text/javascript"> $().ready(function () {// 每增加一个切换,就要增加一行,tab1不变,其他的都 ...
- Android事件的分发
1 http://blog.csdn.net/guolin_blog/article/details/9097463 2
- Python script to create Screen from all Items/Graphs of a host
#!/usr/bin/env python import urllib2 import json import argparse def authenticate(url, username, pas ...
- laravel处理ajax的post提交
Html页面(laravel表单提交必须token)所以 头部要加入: <meta name="csrf-token" content="{{ csrf_token ...
- 自己定义控件三部曲视图篇(二)——FlowLayout自适应容器实现
前言:我最大的梦想,就是有一天.等老了坐在摇椅上回望一生,有故事给孩子们讲--. 相关文章: <Android自己定义控件三部曲文章索引>:http://blog.csdn.net/har ...
- 使用Percona监控插件监控MySQL
1.使用Percona监控插件监控MySQL yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/per ...
- tcp 状态转移图详解
首先看一张图片: 虚线表示服务端的状态转移,实现表示客户端的状态转移. 初始的close状态并不是真是的状态,只是为了方便描述开始和终止状态而构造出来的. 从服务端的状态转移开始说: 服务端打开后处于 ...
- linux 上拷贝文件到windows 上 文件出现锁的文件
要在linux上拷贝出文件到windows上,那么文件必须是777的最高权限. chmod wb_redis -R
- iOS开发之提交App中断出现:Cannot proceed with delivery: an existing transporter instance is currently uploading this package
iOS开发之提交App中断出现:Cannot proceed with delivery: an existing transporter instance is currently uploadin ...