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 ...
随机推荐
- java.math.BigDecimal保留两位小数,保留小数,精确位数
http://blog.csdn.net/yuhua3272004/article/details/3075436 使用java.math.BigDecimal工具类实现 java保留两位小数问题 ...
- zabbix api创建screen vsize限制解决
通过脚本调用zabbix api 生成screen报错: "vsize": must be between "1" and "100" 查看 ...
- docker 让容器执行命令 与 进入容器交互
直接执行命令docker exec mynginx cat /etc/nginx/nginx.conf 进入容器交互docker exec -it 80nginx /bin/bash
- 浅谈BloomFilter【上】基本概念和实现原理
在日常生活中.包括在设计计算机软件时,我们常常要推断一个元素是否在一个集合中. 比方在字处理软件中,须要检查一个英语单词是否拼写正确(也就是要推断 它是否在已知的字典中).在 FBI. ...
- opencv--python--anaconda----contrib 安装
https://pypi.python.org/pypi/opencv-python/3.4.0.12 https://pypi.python.org/pypi?%3Aaction=search&am ...
- poj 2762 Going from u to v or from v to u?(强连通、缩点、拓扑)
题意:(理解错了)在一个洞穴中有多个room,要求任意选两个room:u.v,都能保证u.v之间有通路,注意洞穴中的路是有向边.. 分析:强连通子图中的点必然两两之间可以互通,两个强连通子图之间有通路 ...
- iOS 常用图尺寸 汇总
iCON 准备一张1024x1024尺寸的图,打开链接 http://www.atool.org/ios_logo.php 在线批量生成各种尺寸的图片 启动图LaunchImage 640x960 2 ...
- ConcurrentHashMap的使用和原理
呵呵呵,原理nmb. HashTable,HashMap,ConcurrentHashMap 当你作为一个菜鸡的时候,别人就会那这个来问你. 为什么要用ConcurrentHashMap,因为Hash ...
- ajaxFileUpload 实现多文件上传(源码)
按照原ajaxFileUpload.js是不能多文件上传的.需要对源码进行修改:主要修改了fileElementId部分 具体参考 https://blog.csdn.net/itmyhome1990 ...
- linux下的Java开发 intellij idea+tomcat+maven
前期准备:安装intellij idea.下载tomcat.下载maven(注意我用的是tomcat6.maven 3.2.1.jdk1.6.0_45,之前maven用的3.5结果报错,搞了好久,建议 ...