发布网友
共1个回答
热心网友
#include<stdio.h>
#include<stdlib.h>
typedef struct student
{
int score;
struct student *next;
}student;
student *creatlist()
{
int i=0;
student *head,*p,*q;
head=(student*)malloc(sizeof(student));
p=head;
scanf("%d",&i);
while(i!=-1)
{
q=(student*)malloc(sizeof(student));
q->score=i;
p->next=q;
p=q;
scanf("%d",&i);
}
p->next=NULL;
return head;
}
void print(student *head)
{
if(!head) return;
student *p = head->next;
while(p)
{
printf("%d ",p->score);
p=p->next;
}
}
int main()
{
student *head;
head=creatlist();
print(head);
system("pause");
return 0;
}