116. Populating Next Right Pointers in Each Node

public class Solution {
    public void connect(TreeLinkNode root) {
        TreeLinkNode startNode=root;
        while(startNode!=null)
        {
            TreeLinkNode node=startNode;
            while(node!=null)
            {
                if(node.left!=null)
                    node.left.next=node.right;
                if(node.right!=null&&node.next!=null)
                    node.right.next=node.next.left;
                node=node.next;
            }
            startNode=startNode.left;
        }
    }
}

  

posted @ 2017-09-30 04:54  Weiyu Wang  阅读(118)  评论(0编辑  收藏  举报