public void connect(TreeLinkNode root) {
        if (root==null){
            return;
        }
        TreeLinkNode NextRoot = root.next;
        TreeLinkNode temp = null;
        while (NextRoot!=null){
            if(NextRoot.left!=null){
                temp = NextRoot.left;
                break;
            }
            else if (NextRoot.right!=null){
                temp = NextRoot.right;
                break;
            }
            NextRoot = NextRoot.next;
        }
        if (root.right!=null){
            root.right.next = temp;
        }
        else if(root.left!=null){
            root.left.next = temp;
        }
        if(root.left!=null&&root.right!=null){
            root.left.next = root.right;
        }
        connect(root.right);
        connect(root.left);
    }