http://www.geeksforgeeks.org/inorder-tree-traversal-without-recursion-and-without-stack/

 #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
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 print(node *root) {
if (!root) return;
node *cur = root;
while (cur) {
if (!cur->left) {
cout << cur->data << " ";
cur = cur->right;
}
else {
node *pre = cur->left;
while (pre->right && pre->right != cur) pre = pre->right;
if (pre->right == NULL) {
pre->right = cur;
cur = cur->left;
}
else {
pre->right = NULL;
cout << cur->data << " ";
cur = cur->right;
}
}
}
} void prints(node *root) {
if (!root) return;
prints(root->left);
cout << root->data << " ";
prints(root->right);
} int main() {
node* root = new node();
root->left = new node();
root->right = new node();
root->left->left = new node();
root->left->right = new node();
print(root);
return ;
}

最新文章

  1. IOS
  2. Mastering Web Application Development with AngularJS 读书笔记-前记
  3. 160809209_李梦鑫_C语言程序设计实验2+选择结构程序设计_进阶
  4. code vs1506传话(塔尖)+tarjan图文详解
  5. 最长递增子序列 O(NlogN)算法
  6. Java int to String互转
  7. laravel 5.3 学习之路——路由(资源,别名)
  8. const与#define宏常量 , inline与#define
  9. DEV--GerdView控件
  10. lintcode:字符串置换
  11. URL重写 UrlRewrite
  12. JQuery 补充
  13. UIImageView帧动画相关属性和方法
  14. 小白浅论JAVA数组中“for加强版”
  15. springboot mybatis 整合
  16. 关于SQL的over partition by 开窗语句在分页和统计中的使用总
  17. 1.Django入门
  18. CDH上Cloudera Management Service 各个角色迁移至其他节点
  19. NSString 和 NSData 转换
  20. Python爬虫之requests库介绍(一)

热门文章

  1. oracle的sys密码重置
  2. php url路由伪静态
  3. 调用iPhone的短信
  4. 2010年imac从移动硬盘启动Win10
  5. CSS实现绝对定位居中
  6. iOS端App的icon和Launch Image规格实时更新
  7. Redis用LPUSH和RPOP实现消息队列
  8. Google Code Jam 2014 Round 1 A:Problem A Charging Chaos
  9. 在Ubuntu下利用Eclipse调试FFmpeg
  10. 大数据hadoop之zookeeper