public static void connect(TreeLinkNode root) {
		Queue<TreeLinkNode> q=new ArrayDeque<>();
		if (root!=null) {
			q.offer(root);
		}
		while (!q.isEmpty()) {
			TreeLinkNode p=null, c;
			for (int i=0, n=q.size();i<n;++i) {
				c=q.poll();
				if (p!=null) {
					p.next=c;
				}
				if (c.left!=null) {
					q.offer(c.left);
				} 
				if (c.right!=null) {
					q.offer(c.right);
				}
				p=c;
			}
		}
	}