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的更多相关文章

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

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

  3. Data Structure Binary Tree: Inorder Tree Traversal without Recursion

    http://www.geeksforgeeks.org/inorder-tree-traversal-without-recursion/ #include <iostream> #in ...

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

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

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

  7. Data Structure Binary Tree: Iterative Postorder Traversal

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

  8. Data Structure Binary Tree: Largest Independent Set Problem

    http://www.geeksforgeeks.org/largest-independent-set-problem/ #include <iostream> #include < ...

  9. Data Structure Binary Tree: Morris traversal for Preorder

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

随机推荐

  1. 中小企业 DevOps 从 0 到 1

    原文:http://www.sohu.com/a/145065274_262549 今天主要有四个课题: 先聊一聊 DevOps: 然后跟大家聊一聊运维知识的体系和职业发展: 再是中小企业基于开源的 ...

  2. android tooggle button

    1 http://stackoverflow.com/questions/9938315/toggle-button-in-iphone-style 2 http://blog.csdn.net/bi ...

  3. eclipse / ADT(Android Develop Tool) 一些方便的初始设置

      1.设置编辑窗口的背景色eclipse的主编辑窗口的背景色,默认为白色,个人感觉太亮,推荐保护视力的“墨绿色”,当然也可以根据个人喜好更改,如下图 2.主编辑窗口的字体字号等,也可以根据自己的爱好 ...

  4. HTML css样式

    clear: both清除左侧和右侧浮动 status: 变量状态参数,该属性有5个常用值count 表示当前遍历集合的元素个数index 表示当前遍历到集合的第几个元素current 表示当前的集合 ...

  5. ISE封装IP

    1.综合成ngc文件,然后再黑盒调用,再写一个端口文件(写个空壳文件,就是定义输入输出,在工程里面调用这个文件就行,把ngc放到工程目录下).

  6. Ubuntu 16.04主题美化和软件推荐

    http://www.linuxidc.com/Linux/2016-09/135165.htm http://www.techweb.com.cn/network/system/2015-11-20 ...

  7. inotify+rsync

    backup_to_rsync.sh #!/bin/bash #source function library . /etc/init.d/functions rsync_host=rsync.eti ...

  8. u-boot中断功能初步分析之---------按键中断

    作者:彭东林 邮箱:pengdonglin137@163.com QQ: 405728433 以前一直有个疑问,在U-boot下到底能不能使用中断,为了验证这个问题,于是乎,昨天晚上我在自己的 TQ2 ...

  9. Parencodings - poj 1068

      Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22764   Accepted: 13344 Description L ...

  10. cnn 实例

    http://www.geekcome.com/content-10-3761-1.html http://www.geekcome.com/content-10-3761-1.html http:/ ...