#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
typedef struct student
{
char name[15];
float score;
struct student *next;
}SS;
int len=sizeof(SS);
SS *creat(void)
{
SS *head;
SS *p1,*p2;
p1=p2=(SS *)malloc(len);
scanf("%s %f",&p1->name,&p1->score);
head=p1;
while(p1->score!=-1)
{
p2->next=p1;
p2=p1;
p1=(SS *)malloc(len);
scanf("%s %f",&p1->name,&p1->score);
}
p2->next=NULL;
return head;
}
void hhh(SS *head)
{
SS *p;
p=head;
while(p!=NULL)
{
printf("%s %.1f\n",p->name,p->score);
p=p->next;
}
}
int main()
{
SS *head;
head=creat();
hhh(head);
return 0;
}
PTA7-1 单链表基础应用(1)--创建链表
最新推荐文章于 2023-09-20 20:19:36 发布