117. Populating Next Right Pointers in Each Node II

public class Solution {
    public void connect(TreeLinkNode root) {
        TreeLinkNode lstart=new TreeLinkNode(0);
        while(root!=null)
        {
            TreeLinkNode cur=lstart;
            while(root!=null)
            {
                if(root.left!=null)
                {
                    cur.next=root.left;
                    cur=cur.next;
                }
                if(root.right!=null)
                {
                    cur.next=root.right;
                    cur=cur.next;
                }
                root=root.next;
            }
            root=lstart.next;
            lstart.next=null;
        }
    }
}

  

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