永发信息网

C编程 线性链表的建立

答案:2  悬赏:60  手机版
解决时间 2021-06-02 11:00
  • 提问者网友:城市野鹿
  • 2021-06-01 18:14

这个程序为什么不对呢,无显示的.......

#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
#define N 5
#define LEN sizeof(struct list)
#define NULL 0

struct list
{
float data;
struct list *next;
};

void main()
{
struct list *head;
struct list *p1,*p2;
struct list *p;
int n;
n=0;
p1=p2=(struct list *)malloc(LEN);
printf("please input the first data:");
scanf("%f",&p1->data);
head=NULL;
while(n<N)
{
n++;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct list *)malloc(LEN);
printf("please input the next data:");
scanf("%f",&p1->data);
}
p2->next=NULL;
p=head;
for(n=0;n<N-1;n++)
{
printf("%f->",p->data);
p=p->next;
}

}

最佳答案
  • 五星知识达人网友:西岸风
  • 2021-06-01 18:46
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
#define N 5
#define LEN sizeof(struct list)
#define NULL 0

struct list
{
float data;
struct list *next;
};

void main()
{
struct list *head;
struct list *p1,*p2;
struct list *p;
int n;
n=0;
p1=p2=(struct list *)malloc(LEN);
printf("please input the first data:");
scanf("%f",&p1->data);
head=NULL;
while(n<N)
{
n++;
if(n==1)
head=p1;
p1->next=(struct list *)malloc(LEN);
p1 = p1->next;
printf("please input the next data:");
scanf("%f",&p1->data);
}
p1->next=NULL;
p=head;
for(;p;)
{
printf("%f->",p->data);
p=p->next;
}
}
全部回答
  • 1楼网友:执傲
  • 2021-06-01 20:03

这是c++语言?

比java语言还难应付·

怪不的老师说c++难

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯