C语言链表问题,求解惑

fxfxfxfxw fxfxfxfxw 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include<stdio.h>
struct test
{
int x;
struct test *next;
};
struct test *create(int n)
{
struct test *L, *pnew, *ptail;
int i;
L = (struct test *)malloc(sizeof(struct test *));
pnew = (struct test *)malloc(sizeof(struct test *));
scanf("%d", &pnew->x);
L -> next = pnew;
ptail = pnew;
for (i = 0; i < n - 1; i++)
{
pnew = (struct test *)malloc(sizeof(struct test *));
scanf("%d", &pnew->x);
ptail->next = pnew;
ptail = pnew;
}
pnew->next = NULL;
return L;
}
struct test *MergeList(struct test *La, struct test *Lb)
{
struct test *pa, *pb, *pc,*Lc;
pa = La->next; pb = Lb->next;
Lc=pc = La;
while (pa&&pb)
{
if (pa->x <= pb->x)
{
pc->next = pa;
pc = pa;
pa = pa->next;
}
else
{
pc->next = pb;
pc = pb;
pb = pb->next;
}
}
pc->next = pa ? pa : pb;
free(Lb);
return Lc;
}
void print(struct test *L)
{
struct test *p;
p = L->next;
while (p != NULL)
{
printf("%d\n", p->x);
p = p->next;
}
}
int main()
{
struct test *La,*Lb,*Lc;
int a,b;
printf("请输入需要创建La的链表数:");
scanf("%d", &a);
La= create(a);
printf("请输入需要创建Lb的链表数:");
scanf("%d", &b);
Lb = create(b);
Lc=MergeList(La, Lb);
print(Lc);
}

作用是合并两个非递减链表到Lc中,可是打印不出来,问题试过了,出现在MergeList函数里,单步调试我看局部变量监控是对的啊,可就就是无法用这个函数打印出来
...全文
评论 4
收藏 已收藏
分享
返回顶部
fxfxfxfxw
C语言 70,039 成员 243,237 内容