思想:先将pHead1拿出,pcurA指向phead1的下一个结点,再声明一个
*pCurB;*pNextB;分别指向phead2的当前和下一个结点,每次连接,1不断,2断开。
typedef struct LinkNode{
int data;
LinkNode* pNext;
}LinkNode;
void mergeList(ListNode* headA, ListNode*headB)
{
if(NULL ==headA)
{
return headB;
}
if(NULL ==headB)
{
return headA;
}
LinkNode*pRet;
LinkNode*pCurA;
LinkNode*pCurB;
LinkNode*pNextB;
LinkNode*preA;
pCurA= headA->pNext;
pCurB= pHeadB;
pRet= pHeadA;
preA= pRet;
while(pCurA !=NULL && pCurB != NULL)
{
pNextB= pCurB->pNext;
preA->pNext =pCurB;
pCurB->pNext =pCurA;
preA= pCurA;
pCurB= pNextB;
pCurA= pCurA->pNext;
}
if (pCurA ==NULL)
{
preA->pNext=pCurB;
}
return pRet;
}