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 ;
}

最新文章

  1. [翻译]ES 提案: global
  2. 【转载】wireshark:no interface can be used for capturing in this system with the current configuration
  3. sql里Where条件顺序
  4. 英文论文写作之讨论与结论Discussion and Conclusion
  5. Android 源码编译 步骤
  6. mysql登陆报错(ERROR 2002 (HY000): Can&#39;t connect to local MySQL server through socket &#39;/var/lib/mysql/mysql.sock&#39; (2))
  7. Boost.Asio c++ 网络编程翻译(14)
  8. Oracle基本流程语句
  9. 无法打开物理文件mdf,操作系统错误 5:&amp;quot;5(拒绝訪问。)&amp;quot;
  10. 开涛spring3(7.3) - 对JDBC的支持 之 7.3 关系数据库操作对象化
  11. J2EE进阶(十)SSH框架整合常见问题汇总(一)
  12. qt 视频播放器错误解决方法
  13. PostgreSQL学习笔记(二)-安装pgAdmin
  14. decode函数解决oracle报错&quot;除数为0&quot;的问题
  15. Arrays和String单元测试
  16. 创建react项目
  17. MonGoDB 常见操作, 设置管理员和用户登入
  18. 常用算法1 - 快速排序 &amp; 二分查找
  19. 六种流行的语言大餐---C、C++、python、Java、php、C#你更喜欢哪一个呢?
  20. Php与Erlang的Socket通信

热门文章

  1. EFCore &amp; Mysql migration on Production
  2. shell脚本检测网络是否畅通
  3. Kafka备忘
  4. 2.JAVA编程思想——一切都是对象
  5. PHP运行环境之IIS FastCGI 进程意外退出解决办法
  6. codeforces 427 div.2 F. Roads in the Kingdom
  7. android 国际化 设置
  8. IOS连接
  9. 计算点与x轴正半轴夹角atan2(double y,double x),返回弧度制(-PI,PI]
  10. [Sdoi2013]直径(树的直径)