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

 #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
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) {
stack<node*> S;
if (!root) return;
node *cur = root;
while () {
if (cur) {
S.push(cur);
cur = cur->left;
}
else if (!S.empty()) {
cur = S.top();
S.pop();
cout << cur->data << " ";
cur = cur->right;
}
else break;
}
} int main() {
struct 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 ;
}

Data Structure Binary Tree: Inorder Tree Traversal without Recursion的更多相关文章

  1. 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 ...

  2. Data Structure Binary Tree: Iterative Postorder Traversal

    http://www.geeksforgeeks.org/iterative-postorder-traversal-using-stack/ #include <iostream> #i ...

  3. Data Structure Binary Tree: Morris traversal for Preorder

    http://www.geeksforgeeks.org/morris-traversal-for-preorder/ #include <iostream> #include <v ...

  4. Data Structure Binary Tree: Boundary Traversal of binary tree

    http://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/ #include <iostream> #include & ...

  5. Data Structure Binary Tree: Populate Inorder Successor for all nodes

    http://www.geeksforgeeks.org/populate-inorder-successor-for-all-nodes/ #include <iostream> #in ...

  6. 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 < ...

  7. Data Structure Binary Tree: Level order traversal in spiral form

    http://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/ #include <iostream> #includ ...

  8. Data Structure Binary Search Tree: Inorder Successor in Binary Search Tree

    struct node { int val; node *left; node *right; node *parent; node() : val(), left(NULL), right(NULL ...

  9. Binary Tree Inorder/Preorder Traversal 返回中序和前序/遍历二叉树的元素集合

    给定一个二叉树,以集合方式返回其中序/先序方式遍历的所有元素. 有两种方法,一种是经典的中序/先序方式的经典递归方式,另一种可以结合栈来实现非递归 Given a binary tree, retur ...

随机推荐

  1. MySQL查询缓存设置提高MySQL查询性能

    首先看看MSYQL逻辑框架:图片来自高性能mysql 如果使用了QueryCache,当查询接收到一个和之前同样的查询,服务器将会从查询缓存中检索结果,而不是再次分析和执行相同的查询.这样就能大大提高 ...

  2. Python--多进程--01

    multiprocess import multiprocessing import time def worker_1(interval): print(' i am worker1') n=5 w ...

  3. golang之路:mac下安装go

    1.下载dkg包 2.安装 3.vim .bash_profile export GOROOT=/usr/local/goexport GOPATH=$HOME/GoglandProjects/Pro ...

  4. WebStorm初次使用

    1. ctrl + / : 单行注释2. ctrl + shift + / : 块注释 3:展开当前函数代码:Ctrl+“+”,收起当前代码:Ctrl+“-” 4:全局查找: Ctrl+Shift+F ...

  5. lower_bound() 与 upper_bound()

    1. lower_bound() lower_bound()是泛型算法,在使用时,需要先将序列进行排序: 作用:  函数lower_bound()在first和last中的前闭后开区间进行二分查找,返 ...

  6. OpenCV for Python 学习笔记 三

    给源图像增加边界 cv2.copyMakeBorder(src,top, bottom, left, right ,borderType,value) src:源图像 top,bottem,left, ...

  7. erlang的非平衡的二叉树的操作

    -module(tree1). -export([test1/0]). lookup(Key,nil) -> not_found; lookup(Key,{Key,Value,_,_}) -&g ...

  8. php 生成8位数唯一的激活码

    /** *生成激活码 */ function showGenerationActivationCode(){ #渠道类型id $channel_id=$_POST['channel']; #根据渠道i ...

  9. 中国版Office 365混合部署功能

    中国版Office 365混合部署功能已经正式上线了(原计划6月份推出),虽然支持的类型不如国际版的Office 365全面,但这也标志了该功能与之前相比,已经迈出了重要一步.目前中国版Office ...

  10. oracle10g卸载问题

    oracle10g卸载是一个比较麻烦的事,一般要完全卸载有以下几个步骤: 实现方法:1.开始->设置->控制面板->管理工具->服务停止所有Oracle服务:2.开始-> ...