leetcode Populating Next Right Pointers in Each Node

/**
根据完美二叉树或者非完美二叉树都可以,利用左右子树的根节点的next节点信息来连接next
*/
public
void connect(TreeLinkNode root){ if(root==null) return; //利用父节点的next链接节点 if(root.left!=null){ root.left.next=root.right; } if(root.right!=null&&root.next!=null){ root.right.next=root.next.left; } connect(root.left); connect(root.right); }

 

posted @ 2014-05-20 11:18  曹守鑫  阅读(134)  评论(0编辑  收藏  举报