C语言定义一个头节点,一个关于C语言链表头结点的问题
該樓層疑似違規(guī)已被系統(tǒng)折疊?隱藏此樓查看此樓
#include
#include
#include
typedef struct STU{
int sno;
char sname[10];
float grade;
struct STU *next;
}STU;
STU *inputData(); /*創(chuàng)建鏈表,返回鏈表的頭指針*/
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)
{
___________________________________________; /*輸出數(shù)據(jù)*/
p=p->next;
}
}
總結
以上是生活随笔為你收集整理的C语言定义一个头节点,一个关于C语言链表头结点的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c语言吗 程序语言,编程语言为什么从c语
- 下一篇: 如题,用C#语言 如何给下拉列表框动态添