Data Structure Binary Tree: Populate Inorder Successor for all nodes
http://www.geeksforgeeks.org/populate-inorder-successor-for-all-nodes/
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
using namespace std; struct node {
int data;
struct node *left, *right, *next;
node() : data(), left(NULL), right(NULL), next(NULL) { }
node(int d) : data(d), left(NULL), right(NULL), next(NULL) { }
}; void populate(node *root) {
static node *next = NULL;
if (!root) return;
populate(root->right);
root->next = next;
next = root;
populate(root->left);
} int main() {
node *root = new node();
root->left = new node();
root->right = new node();
root->left->left = new node();
populate(root);
cout << root->data << "->" << (root->next? root->next->data : -) << endl;
cout << root->left->data << "->" << (root->left->next? root->left->next->data : -) << endl;
cout << root->right->data << "->" << (root->right->next? root->right->next->data : -) << endl;
cout << root->left->left->data << "->" << (root->left->left->next? root->left->left->next->data : -) << endl;
return ;
}
Data Structure Binary Tree: Populate Inorder Successor for all nodes的更多相关文章
- 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: 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 ...
- Data Structure Binary Tree: Convert a given Binary Tree to Doubly Linked List
http://www.geeksforgeeks.org/in-place-convert-a-given-binary-tree-to-doubly-linked-list/ #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: Largest Independent Set Problem
http://www.geeksforgeeks.org/largest-independent-set-problem/ #include <iostream> #include < ...
- Data Structure Binary Tree: Morris traversal for Preorder
http://www.geeksforgeeks.org/morris-traversal-for-preorder/ #include <iostream> #include <v ...
随机推荐
- The Application does not have a valid signature
真机运行程序,报错(The application does not have a valid signature,如图 环境:Xcode7.3,使用cocoapods管理第三方库 如果确认证书没有问 ...
- c#关于int(或其他类型)的字段在对象初始化时默认初始化问题的解决方法
问题: c#的wcf服务接口在后台通过自定义对象接收前台参数的时候,前台参数即使不传int类型的字段值,后台也会默认初始化为0,由于很多表示状态的int字段都是从0开始的,导致查询的时候有些不想参与查 ...
- df 命令
linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息. 1.命令格式: df [选项] [文件] 2.命 ...
- NHibernate二级缓存(第十一篇)
NHibernate二级缓存(第十一篇) 一.NHibernate二级缓存简介 NHibernate由ISessionFactory创建,可以被所有的ISession共享. 注意NHibernate查 ...
- Hdu 5288 OO’s Sequence 2015多小联赛A题
OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 《TomCat与Java Web开发技术详解》(第二版) 第五章节的学习总结 ---- Servlet的高级用法
这一章节主要是介绍了Servlet技术的一些高级用法,如下是我自己的整理归纳 1.下载文件:即获取服务器文件,并把文件写入反馈给客户端 ServletContext.getResourceAsStre ...
- 不可忽略的apache 的 Keep Alive
转载链接:http://hi.baidu.com/jx_iben/item/d5fe91feed74495ec9f337f1 在网页开发过程中,Keep-Alive是HTTP协议中非常重要的一个属性. ...
- 蒙特卡洛方法计算圆周率的三种实现-MPI openmp pthread
蒙特卡洛方法实现计算圆周率的方法比较简单,其思想是假设我们向一个正方形的标靶上随机投掷飞镖,靶心在正中央,标靶的长和宽都是2 英尺.同时假设有一个圆与标靶内切.圆的半径是1英尺,面积是π平方英尺.如果 ...
- 从零开始学android -- dialog
先看个效果图 activity_main.xml <?xml version="1.0" encoding="utf-8"?> <Linear ...
- Android Studio 2.0 稳定版新特性介绍
Android Studio 2.0 最终迎来了稳定版本号,喜大普奔. 以下这篇文章是2.0新特性的一些简介. 假设想看具体内容请看这里<Android Studio有用指南> 文章转自这 ...