mocherry123 2016-10-11 11:25 采纳率: 0%
浏览 844

这个程序运行不了 可是没看出错误 求帮看一下

#include
#include

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

void InitList (LinkList L)
{
L=(LinkList)malloc (sizeof(LNode));
L->next = NULL;
}

void UpList(LinkList L, int x)
{
LinkList p = L;
while(p->next)
{
p=p->next;
}

LinkList temp = (LinkList)malloc(sizeof(LNode));
temp->data = x;
temp->next = NULL;
p->next = temp;

}

void DisList(LinkList L)
{
LinkList p = L->next;
while(p!=NULL)
{
printf("%c",p->data);
p=p->next;
}
}

void DestroyList(LinkList L)
{
LinkList p = L,q = p->next;
while(q!=NULL)
{
free(p);
p = q;
q = p->next;
free(p);
}
}

int Listlength(LinkList L)
{
if (L==NULL) {
return 0;
}
LinkList p = L;
int a = 0;
while(p->next!=NULL)
{
a++;
p = p->next;
}
return (a);
}

void StickList (LinkList ha,LinkList hb,LinkList hc ,int m,int n)
{
LinkList p = NULL;
if(m==0)
{
hc=hb;
free(ha);
}

else if(n==0)
{
    hc=ha;
    free(hb);
}

else if(m<n)
{
    p=ha->next;
    while(p->next != NULL)
        p=p->next;
    p->next = hb->next;
    hc=ha;
    free(hb);
}

else
{
    p=hb->next;
    while(p->next!=NULL)
        p=p->next;
    p->next = ha->next;
    hc=hb;
    free(ha);
}

}

int main() {

LinkList ha, hb, hc;
InitList(ha);

InitList(hb);
InitList(hc);

for (int i = 0;i<100;i++)
    UpList(ha,i);
printf("链表ha的元素有\n");
DisList(ha);
int m = Listlength(ha);

for(int j=0;j<100;j++)
    UpList(hb,j);
printf("链表hb的元素有\n");
DisList(hb);
int n = Listlength(hb);

StickList(ha,hb,hc, m, n);
printf("链表hc的元素有\n");
DisList(hc);
return 0;

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-10-11 11:34
    关注
     void InitList (LinkList L)
    {
        L=(LinkList)malloc (sizeof(LNode));
        L->next = NULL;
    }
    
    这里就错了,你在函数里改变L,不会作用到实参上,你得用指针的指针。
    InitList(ha);
    此后ha还是null
    
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型