该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include
typedef struct STU{
int sno;
char sname[10];
float grade;
struct STU *next;
}STU;
STU *inputData(); /*创建链表,返回链表的头指针*/
void printData( STU *list); /*输出链表*/
int main()
{
STU *h=NULL;
h=inputData();
printData(h);
return 0;
}
STU *inputData()
{
STU *p=NULL,*q=NULL,*head=NULL;
int sno;
char sname[10];
float grade;
scanf("%d%s%f",&sno,sname,&grade);
while(sno!=-1) /*输入学号为-1时,结束输入*/
{
p=(STU *)malloc(sizeof(STU));
p->sno=sno;
strcpy(p->sname,sname);
p->grade=grade;
p->next=NULL;
if(head==NULL)
head=p;
else
q->next=p;
q=p;
scanf("%d%s%f",&sno,sname,&grade);
}
return head;
}
void printData( STU *list)
{
STU *p=list;
printf("\n======================\n");
while(p!=NULL)
{
___________________________________________; /*输出数据*/
p=p->next;
}
}