首页 > 其他 > 详细

Populating Next Right Pointers in Each Node

时间:2014-03-22 13:23:19      阅读:217      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣

 1     //按说层次遍历最方便了,但是空间复杂度不满足题意
 2     //遍历吧,可是像例子中的,5—>6怎么实现呢
 3     //You may assume that it is a perfect binary tree (ie, all leaves are at the same level, and every parent has two children).
 4     //这个提示是什么意思?
 5     void connect(TreeLinkNode *root) {
 6         if(root==NULL)
 7             return;
 8         if(root->left)
 9             root->left->next=root->right;
10         if(root->next&&root->right)
11             root->right->next=root->next->left;
12         connect(root->left);
13         connect(root->right);
14         //Initially, all next pointers are set to NULL.因为这句话,所以根节点的next和最右结点的next就不用指定为NULL啦
15     }
bubuko.com,布布扣

AC

参看http://blog.csdn.net/fightforyourdream/article/details/14514165

Populating Next Right Pointers in Each Node,布布扣,bubuko.com

Populating Next Right Pointers in Each Node

原文:http://www.cnblogs.com/crane-practice/p/3617226.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!