public void connect(TreeLinkNode root) {
        if(root == null){
            return;
        }
        LinkedList<TreeLinkNode> queue = new LinkedList<TreeLinkNode>();
        LinkedList<TreeLinkNode> childQueue = new LinkedList<TreeLinkNode>();
        queue.add(root);
        TreeLinkNode preNode = null;
        while (!queue.isEmpty()){
            TreeLinkNode node = queue.remove();
            if(preNode != null){
                preNode.next=node;
            }
            preNode = node;
            if(node.left != null){
                childQueue.add(node.left);
            }
            if(node.right!=null){
                childQueue.add(node.right);
            }
            if(queue.isEmpty() && !childQueue.isEmpty()){
                queue.addAll(childQueue);
                childQueue.clear();
                preNode=null;
            }
        }
    }