The combined operation of the common list list

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/Nash_Cyk/article/details/79083101

Recursive thinking, stitching two lists!

//链表合并 递归方式
LIST_NODE * MergeList(LIST_NODE *m_pHead1,LIST_NODE *m_pHead2)
{
    LIST_NODE *MergeListHead  = NULL;
    if (m_pHead1 == NULL)
    {
        return m_pHead2;
    }
    if (m_pHead2 == NULL)
    {
        return m_pHead1;
    }

    if (m_pHead1->num < m_pHead2->num)
    {
        MergeListHead = m_pHead1;
        MergeListHead->next = MergeList(m_pHead1->next,m_pHead2);
    }
    else
    {
        MergeListHead = m_pHead2;
        MergeListHead->next = MergeList(m_pHead1,m_pHead2->next);
    }
    return MergeListHead;
}

Guess you like

Origin blog.csdn.net/Nash_Cyk/article/details/79083101