private ListNode merge(ListNode listA, ListNode listB)
    {
    	if(listA == null) return listB;
    	if(listB == null) return listA;
    	
    	ListNode newHeadA = listA;
    	ListNode nextA, nextB, preA;
    	preA = nextA = listA;
    	nextB = listB;
    	while ((nextA!=null) && (nextB!=null))
    	{
    		if(nextB.val < nextA.val)
    		{
    			if(preA == nextA)//smaller than the first item in listA
    			{
    				newHeadA = nextB;
    				nextB = nextB.next;
    				preA = newHeadA;
    				newHeadA.next = nextA;
    			}
    			else
    			{
    				preA.next = nextB;
    				nextB = nextB.next;
    				preA = preA.next;
    				preA.next = nextA;
    			}
    		}
    		else
    		{
    			preA = nextA;
    			nextA = preA.next;
    		}
    	}
    	
    	if (nextA == null)
    		preA.next = nextB;

    	return newHeadA;
    		
    }