// 寫一個函數,建立一個有三個學生數據的動態鏈表.動態鏈表的深奧程度真心可以。大家加油啊
//
#include<stdio.h>
#include<stdlib.h>
#define len sizeof(struct Student)
struct Student
{
int num;
float score;
struct Student *next;
};
int n;
struct Student *creat(void)
{
struct Student *head,*p1,*p2;
n=0;
p1=p2=(struct Student *)malloc(len);
scanf("%d %f",&p1->num,&p1->score);
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct Student*)malloc(len);
scanf("%d %f",&p1->num,&p1->score);
}
p2->next=NULL;
return (head);
}
int main()
{
struct Student *pt;
pt=creat();
printf("%d %f",pt->num,pt->score);
return 0;
}
處理全班學生的成績--動態鏈表
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
將一個鏈表逆序並輸出
toigel
2019-02-23 13:38:11
嵌入式Linux C語言基礎——ARM Linux內核常見數據結構
159789zhong
2019-02-22 23:41:16
C++實現鏈表的基本操作及測試用例
myideatt
2019-02-22 23:35:53
在matlab中實現鏈表
liyu_h
2019-02-22 23:02:33
順序棧與鏈表棧的實現
君峯俊宇
2019-02-22 22:30:50
C語言 單鏈表的實現
君峯俊宇
2019-02-22 22:30:49
複製含有隨機指針節點的鏈表
天一涯51CTO
2019-02-22 21:41:29
比較分析與數組相關的sizeof和strlen
言安陽
2019-02-22 23:37:24
名詞:topology、architecture和struct,究竟什麼纔是架構?
一見_
2019-02-23 00:16:35