Data Structure Binary Tree: Inorder Tree Traversal without Recursion
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的更多相关文章
- 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: Iterative Postorder Traversal
http://www.geeksforgeeks.org/iterative-postorder-traversal-using-stack/ #include <iostream> #i ...
- Data Structure Binary Tree: Morris traversal for Preorder
http://www.geeksforgeeks.org/morris-traversal-for-preorder/ #include <iostream> #include <v ...
- 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: Populate Inorder Successor for all nodes
http://www.geeksforgeeks.org/populate-inorder-successor-for-all-nodes/ #include <iostream> #in ...
- 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: Level order traversal in spiral form
http://www.geeksforgeeks.org/level-order-traversal-in-spiral-form/ #include <iostream> #includ ...
- 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 ...
- Binary Tree Inorder/Preorder Traversal 返回中序和前序/遍历二叉树的元素集合
给定一个二叉树,以集合方式返回其中序/先序方式遍历的所有元素. 有两种方法,一种是经典的中序/先序方式的经典递归方式,另一种可以结合栈来实现非递归 Given a binary tree, retur ...
随机推荐
- java 页面错误转发提示页面 errorPage转跳报HTTP500内部服务器错误
errorPage和isErrorPage本来是很简单的功能,但是我却没弄出来,还百度了半天,结果发现是IE的设置问题.将下图中的“Show friendly HTTP error messages( ...
- Android_Fragment_Fragment详解
Android_Fragment_Fragment详解 分类: Android基础2013-10-03 08:23 92人阅读 评论(0) 收藏 举报 AndroidFragmentFragmen ...
- mfs客户端挂载
1.安装fuse yum install fuse fuse-devel 2.加载fuse模块 modprobe fuse 3.创建mfs用户 useradd mfs -s /sbin/nologin ...
- cache和buffer区别探讨
一. 1.Buffer(缓冲区)是系统两端处理速度平衡(从长时间尺度上看)时使用的.它的引入是为了减小短期内突发I/O的影响,起到流量整形的作用.比如生产者——消费者问题,他们产生和消耗资源的速度大体 ...
- 获取、增加、修改、删除sqlserver字段描述及快速查看表字段与描述
先看添加与删除字段描述 EXEC sys.sp_addextendedproperty @name = N'MS_Description', --添加Type字段说明 @value = N'屏蔽类型对 ...
- JS 手势长按代码
同时支持长按和点击事件,无依赖版 <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- appearance 设置公共属性
//设置公共TabBarItem 的属性 [UITabBarItem appearance] //设置公共NavigationBar 的属性 [UIBarButtonItem appearance]
- 使用mescroll实现上拉加载与下拉刷新
现在上拉加载与下拉刷新几乎已经是移动端必备功能之一了,自己实现一个太麻烦,但是好用的插件又非常少.之前看到网上很多人都在用iScroll,于是也尝试用它做了几个DEMO,但或多或少都有一些问题,比如这 ...
- 下载yum安装的rpm包
方法一 通过yum自带的yumdownloader工具进行下载,这个工具是由yum-utils这个软件安装生成的 执行如下命令,检查yum-utils是否存在: rpm -qa |grep yum-u ...
- ffmpeg保存原始数据PCM YUV
保存yuv ffmpeg -i video.mp4 -c:v rawvideo -pix_fmt yuv420p out.yuv 保存pcm ffmpeg -i input.flv -f s16le ...