链表合并-带头结点尾插
nbb / 2022-03-08 / 刷题 / 阅读量 752
List Merge(List L1, List L2) {
    List DummyHead = (List) calloc(1,sizeof(List));
    List pa = DummyHead, p1 = L1->Next, p2 = L2->Next;
    L1->Next = NULL;
    L2->Next = NULL;
    while (p1 || p2) {
        if (!p1) {
            pa->Next = p2;
            break;
        } else if (!p2) {
            pa->Next = p1;
            break;
        } else {
            if (p1->Data <= p2->Data) {
                pa->Next = p1;
                p1 = p1->Next;
            } else {
                pa->Next = p2;
                p2 = p2->Next;
            }
            pa = pa->Next;
        }
    }
    return DummyHead;
}