改编C语言程序

来源:百度知道 编辑:UC知道 时间:2024/06/08 15:32:00
增加一个node成员
#include<stdlib.h>
#include<stdio.h>
Struct node
{
int num;
Struct node *next;
};
Void main()
{struct node *create();
void print();
Struct node *head;
head=NULL;
head=create(head);
Print(head);
}
Struct node *create(struct node *head)
{struct node *p1,*p2;
p1=p2=(struct node *)malloc(sizeof(struct node));
Scanf("%d",&p1->num);
p1->next=NULL;
while(p1->num!=-999)
{if(head==NULL)head=p1;
else p2->next=p1;
p1=p2;
p1=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p1->num);
p1->next=NULL;
}
return head;
}
void print(struct node *head)
{struct node *temp;
temp=head;
while(temp!=NULL)
{printf("%6d",temp->num);
temp=temp->next;
}
}

嗯。确实有很多大小写错误
create和print两个函数的声明,都少参数

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

struct node
{
int num;
struct node *next;
};

void main()
{
struct node *create(struct node *head); //函数声明写参数类型
void print(struct node *head); //函数声明写参数类型

struct node *head;

head=NULL;
head=create(head);
print(head);
}

struct node *create(struct node *head)
{
struct node *p1,*p2;

p1=p2=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p1->num);
p1->next=NULL;
while(p1->num!=-999)
{
if(head==NULL)head=p1;
else p2->next=p1;
p1=p2;
p1=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p1->num);
p1->next=NULL;
}
return head;
}

void print(struct node *head)
{
struct node *temp;

te