程序在Dev里有时可以正常运行 有时读不进去东西 在pta里面交的话是编译错误
#include <stdio.h>
#include <stdlib.h>
struct stud_node {
int num;
char name[20];
int score;
struct stud_node *next;
};
struct stud_node *createlist();
struct stud_node *deletelist( struct stud_node *head, int min_score );
int main()
{
int min_score;
struct stud_node *p, *head = NULL;
head = createlist();
scanf("%d", &min_score);
head = deletelist(head, min_score);
for ( p = head; p != NULL; p = p->next )
printf("%d %s %d\n", p->num, p->name, p->score);
return 0;
}
/* 你的代码将被嵌在这里 */
struct stud_node *createlist()
{
stud_node *p,*head=(struct stud_node *)malloc(sizeof(struct stud_node*));
p=head;
int a;
scanf("%d",&a);
while(a!=0)
{
p->num=a;
scanf("%s%d",p->name,&p->score);
p->next=NULL;
scanf("%d",&a);
if(a)
{
p->next=(struct stud_node *)malloc(sizeof(struct stud_node *));
p=p->next;
}
else
break;
}
return head;
}
struct stud_node *deletelist( struct stud_node *head, int min_score )
{
struct stud_node *b,*p=head,*head1=head;
int first=1;
while(p!=NULL)
{
if(p->score<min_score)
{
if(first)
{
head1=p->next;
}
else
{
b->next=p->next;
free(p);
p=b->next;
continue;
}
}
else
{
first=0;
}
b=p;
p=p->next;
}
return head1;
}