天天看點

C語言定義一個頭節點,一個關于C語言連結清單頭結點的問題

該樓層疑似違規已被系統折疊 隐藏此樓檢視此樓

#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)

{

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;

}

}