Data Structure Binary Tree: Morris traversal for Preorder
http://www.geeksforgeeks.org/morris-traversal-for-preorder/
#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) {
while (root) {
if (root->left == NULL) {
cout << root->data << " ";
root = root->right;
}
else {
node* cur = root->left;
while (cur->right && cur->right != root) cur = cur->right;
if (cur->right == NULL) {
cout << root->data << " ";
cur->right = root;
root = root->left;
}
else {
cur->right = NULL;
root = 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();
root->right->left = new node();
root->right->right = new node();
root->left->left->left = new node();
root->left->left->right = new node();
root->left->right->left = new node();
root->left->right->right = new node();
prints(root);
return ;
}
Data Structure Binary Tree: Morris traversal for Preorder的更多相关文章
- 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: Iterative Postorder Traversal
http://www.geeksforgeeks.org/iterative-postorder-traversal-using-stack/ #include <iostream> #i ...
- 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: Construct Tree from given Inorder and Preorder traversals
http://www.geeksforgeeks.org/construct-tree-from-given-inorder-and-preorder-traversal/ #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: Level order traversal in spiral form
http://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/ #include <iostream> #includ ...
- 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: 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 ...
随机推荐
- 02-2设置第一启动项--进入Bios界面设置U盘为第一启动项
进入Bios界面设置U盘为第一启动项: 开机,当电脑处于启动状态,屏幕显示电脑LOGO时,按下F2键.(根据电脑的不同,进入BIOS的功能键也不同,可根据自己电脑的型号百度搜索相关功能键) 按电脑方向 ...
- 深入理解dp px density
1 http://blog.csdn.net/lcaihy1314/article/details/8446401 2 待续
- CentOS4.5下LVS方案
环境描述:本文在配置LVS时使用三台linux,一台做Directorserver (192.168.0.25) ,两台做realserver(192.168.0.127 192.168.0.12,在 ...
- java之数字彩虹雨
© 版权声明:本文为博主原创文章,转载请注明出处 数字彩虹雨: 从上至下,随机出现一串字符串,以不同的速度运行到底部:类似于黑客帝国里面的场景 GitHub:https://github.com/Ta ...
- LINQ使用与并行
LINQ介绍 參考:https://msdn.microsoft.com/en-us/library/bb397906.aspx LINQ查询主要运行操作包含:1)获取数据源:2)创建查询:3)运行查 ...
- 解决ajax跨域问题的多种方法
//第一种方法使用jsonp的方式 <script type="text/javascript" src="http://www.youxiaju.com/js/j ...
- 01 linux上安装 nginx
一:linux上安装 nginx 下载nginx:wget http://nginx.org/download/nginx-1.6.2.tar.gz 解压:tar zxvf nginx-1.6.2.t ...
- 【转】Jenkins+Ant+Jmeter接口自动化集成测试实例
出处:https://my.oschina.net/MrToStudy/blog/742251 一.Jenkins安装配置 1.安装配置JDK1.6+环境变量: 2.下载jenkins.war,放入C ...
- 计算CPU利用率
一般来说对于需要大量cpu计算的进程,当前端压力越大时,CPU利用率越高.但对于I/O网络密集型的进程,即使请求很多,服务器的CPU也不一定很到,这时的服务瓶颈一般是在磁盘的I/O上.比较常见的就是, ...
- 微信小程序之如何注册微信小程序
所有文章均是CSDN博客所看,已按照作者要求,注明出处了,感谢作者的整理! 博客文章地址:http://blog.csdn.net/michael_ouyang/article/details/546 ...