public void connect(TreeLinkNode root) {
    	if (root == null)
    		return;
        LinkedList<TreeLinkNode> list = new LinkedList<TreeLinkNode>();
        list.add(root);
        while (!list.isEmpty()) {
        	int n = list.size();
        	TreeLinkNode pre = null;
        	for (int i = 0; i < n; i++) {
        		if (i == 0) {
        			pre = list.get(0);
        			if (pre.left != null) list.add(pre.left);
        			if (pre.right != null) list.add(pre.right);
        		} else {
        			TreeLinkNode cur = list.get(0);
        			pre.next = cur;
        			if (cur.left != null) list.add(cur.left);
        			if (cur.right != null) list.add(cur.right);
        			pre = cur;
        		}
        		list.removeFirst();
        	}
        }
    }