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. 使用lua扩展应用程序

    全局变量的操作 void lua_getglobal(lua_State * L ,const char * name) 此函数从lua中取出一个名为name的全局变量并将其压入栈中. 如当lua文件 ...

  2. UIViewController新方法的使用(transitionFromViewController:toViewController:duration:options:animations:completion:)

    iOS5中,UIViewController新添加了几个方法: - (void)addChildViewController:(UIViewController *)childController N ...

  3. vim 命令行使用技巧

    1. <Ctrl-U> <Ctrl-K> 删除光标到开头的输入 2. <Ctrl-W> 删除最近输入的单词 3. <Ctrl-H> 删除光标之前的一个字 ...

  4. 【已解决】 iView-admin 动态路由问题

    IView-admin 在使用的时候 跳转客户详细后,点击其它页面,然后再从选项卡进入页面时,发下控制台 报错,不能正常打开客户详细页面 [vue-router] Route with name 'c ...

  5. 解析spark RDD

    RDD是spark抽象的基石,可以说整个spark编程就是对RDD进行的操作   RDD是弹性的分布式数据集,它是只读的,可分区的,这个数据集的全部或者部分数据可以缓存在内存中,在多次计算间重用.所谓 ...

  6. 2013 年最好的 20 款免费 jQuery 插件

    2013 年最好的 20 款免费 jQuery 插件 oschina 发布于: 2014年01月11日 (8评) 分享到  新浪微博腾讯微博 收藏+99 互联网上面有很多 jQuery 插件,这里我们 ...

  7. 【Mysql】Navicat For Mysql快捷键

    ctrl+q 打开查询窗口ctrl+/ 注释sql语句ctrl+shift +/ 解除注释ctrl+r 运行查询窗口的sql语句ctrl+shift+r 只运行选中的sql语句F6 打开一个mysql ...

  8. python selenium - SSL处理(https)

    在实际的自动化测试实践中,因为越来越多的站点接入https,使得我们原有的python selenium2自动化测试代码进行测试时,浏览器总是报安全问题,即便在浏览器选项中将被测网址加入信任网址也没用 ...

  9. html5小趣味知识点系列(二)tabindex

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. hdu 4902 Nice boat(线段树区间改动,输出终于序列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 Problem Description There is an old country and ...