合併兩個有序鏈表

 

 1 struct ListNode{  2     int m_Value;  3     ListNode *m_pNext;  4 };  5 
 6 ListNode *Merge(ListNode *pHead1,ListNode *pHead2){  7     if(pHead1==NULL)  8     return pHead2;  9     else if(pHead2==NULL) 10     return pHead1; 11     
12     ListNode *pMergedHead=NULL; 13     if(pHead1->m_Value<pHead2_m_Value){ 14         pMergedHead=pHead1; 15         pMergedHead=>m_pNext=Merge(pHead1->m_pNext,pHead2); 16  } 17     else{ 18         pMergedHead=pHead2; 19         pMergedHead->m_pNext=Merge(pHead1,pHead2->m_pNext); 20  } 21     return pMergedHead; 22 }

 

 

 

參考資料:https://www.cnblogs.com/jason2013/articles/4341153.htmlhtml

相關文章
相關標籤/搜索