出现value 3221225477

Andy_Ta 2020-03-30 05:12:27

这是问题


#include<stdio.h>
#include<stdlib.h>

typedef struct node{
int height;
struct node *next;
}linklist;

linklist *CreateList()
{
linklist *head=(linklist *)malloc(sizeof(linklist));
head->next=NULL;
return head;
}

void ini(linklist *head,int num)
{
linklist *s,*r;
r=head;
int i;
for (i=0;i<num;i++)
{
s=(linklist*)malloc(sizeof(linklist));
scanf("%d",&s->height);
r->next=s;
r=s;
}
r->next=NULL;
}

void insert(linklist *head,int h)
{
linklist *p,*q,*z;
q=head;
p = (linklist *)malloc(sizeof(linklist));
p->height=h;
while(q->next && q->next->height<h)
{
q=q->next;
}
if (q->next==NULL)
{
q->next=p;
p->next=NULL;
}
else
{
z=q->next;
q->next=p;
p->next=z;
}
}

void Output(linklist *head)
{
linklist *p=head->next;
printf("%d",p->height);
while(p!=NULL)
{
p=p->next;
printf(" %d",p->height);
}
}

int main()
{
int num,number;
linklist *L;
L=CreateList();
scanf("%d%d",&num,&number);
ini(L,num);
insert(L,number);
Output(L);
return 0;
}
我的代码



网上搜索了一下说是有溢出或是未初始化,但小弟实在没发现问题呀,运行结果是ok的。
...全文
970 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Andy_Ta 2020-04-02
  • 打赏
  • 举报
回复
谢谢大家帮忙
自信男孩 2020-04-01
  • 打赏
  • 举报
回复
#include<stdio.h>
#include<stdlib.h>

typedef struct node{
int height;
struct node *next;
}linklist;

linklist *CreateList()
{
linklist *head=(linklist *)malloc(sizeof(linklist));
head->next=NULL;
return head;
}

void ini(linklist *head,int num)
{
linklist *s,*r;
int i;

r = head;
for (i=0;i<num;i++)
{
s=(linklist*)malloc(sizeof(linklist));
if (!s)
exit(0);
scanf("%d",&s->height);
r->next = s;
r=s;
}
r->next=NULL;
}

void insert(linklist *head,int h)
{
linklist *p,*q,*z;
q = head;
p = (linklist *)malloc(sizeof(linklist));
if (!p)
exit(0);
p->height = h;
while(q->next && q->next->height < h)
{
q = q->next;
}

p->next = q->next;
q->next = p;

#if 0
if (q->next==NULL)
{
q->next=p;
p->next=NULL;
}
else
{
z=q->next;
q->next=p;
p->next=z;
}
#endif
}

void Output(linklist *head)
{
linklist *p=head->next;
while(p!=NULL)
{
printf("%d ",p->height);
p=p->next;
//printf(" %d",p->height);
}
}

int main()
{
int num,number;
linklist *L;
L=CreateList();
scanf("%d%d",&num,&number);
ini(L, num);
insert(L,number);
Output(L);
return 0;
}

供参考~
chxchxkkk 2020-03-30
  • 打赏
  • 举报
回复

void Output(linklist *head)
{
    linklist *p=head->next;
    printf("%d",p->height);
    while(p!=NULL)
    {
        printf(" %d",p->height);
        p=p->next;
       // printf(" %d",p->height); 这句放到上面就没有问题了	
    }
}

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧