public void connect(TreeLinkNode root) {
    	if(root==null) return; 
    	TreeLinkNode cur = root; 
    	TreeLinkNode prev = null;
    	TreeLinkNode leftMost = null; 
    	while(cur!=null)
    	{
    		if(cur.left!=null) 
    		{
    			if(prev != null)prev.next = cur.left;
    			prev = cur.left;
    			if(leftMost == null)leftMost = cur.left;
    		}
    				
    		if(cur.right!=null)
    		{
    			if(prev != null)prev.next = cur.right;
    			prev = cur.right;
    			if(leftMost == null)leftMost = cur.right;
    		}
    				
    		cur = cur.next;
    	}
    	
    	connect(leftMost);
    }