Mac上的Clion运行C++问题

进行创建两个有序链表并将有序其合并问题
#include <iostream>

typedef int ElemType;
typedef struct LNode
{
    ElemType data;
    struct LNode *next;
}LNode,*LinkList;

void CreatSortLink(LinkList &L)
{
    int x;
    LNode *pnew;
    LNode *ppre;
    LNode *pcur;
    L = (LNode *)malloc(sizeof(LNode));
    L->next = NULL;
    scanf("%d",&x);
    while(x != 9999)
    {
        pnew = (LNode *)malloc(sizeof(LNode));
        pnew->data = x;
        ppre = L;
        pcur = L -> next;
        if(L -> next == NULL)
        {
            L -> next = pnew;
            pcur = pnew;
            pcur -> next = NULL;
        }
        while(pnew -> data > pcur -> data)
        {
            if(pcur -> next == NULL)
            {
                pcur -> next = pnew;
                pnew -> next = NULL;
                continue;
            }
            ppre = pcur;
            pcur = pcur -> next;
        }
        if(pnew -> data < pcur -> data)
        {
            ppre -> next = pnew;
            pnew -> next = pcur;
        }
        scanf("%d",&x);
    }
}


void PrintList(LinkList L)
{
    while(L -> next != NULL)
    {
        L = L -> next;
        printf("%d",L->data);

    }
}

void LinkListMerge(LinkList L,LinkList S)
{
    LNode *pnew,*ppre,*pcur;
    while(S -> next != NULL)
    {
        pnew = S -> next;
        S = S -> next;
        ppre = L;
        pcur = L->next;
        while (pnew->data > pcur->data)
        {
            if (pcur->next == NULL)
            {
                pcur->next = pnew;
                pnew->next = NULL;
                continue;
            }
            ppre = pcur;
            pcur = pcur->next;
        }
        if (pnew->data < pcur->data)
        {
            ppre->next = pnew;
            pnew->next = pcur;
        }
    }
}
int main()
{
    LinkList L,S;
    CreatSortLink(L);
    PrintList(L);
    printf("\n");
    CreatSortLink(S);
    PrintList(S);
    printf("\n");
    LinkListMerge(L,S);
    PrintList(L);
    return 0;
}

通过调试得知在调用LinkListMerge 函数中出现了错误,截图为此过程的问题调试,当表S的头节点指针后的指针pnew发生改变时,表S头节点S指针立马发生改变,不知什么原因

img

我尝试第一个链表输入 1 3 5 第二个链表输入 2 4 6 输出结果为 1 2 3 5
期望结果为123456