6-4 建立学生信息链表 (20 分)
生活随笔
收集整理的這篇文章主要介紹了
6-4 建立学生信息链表 (20 分)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本題要求實現一個將輸入的學生成績組織成單向鏈表的簡單函數。
函數接口定義:
該函數利用scanf從輸入中獲取學生的信息,并將其組織成單向鏈表。鏈表節點結構定義如下:
struct stud_node {int num; /*學號*/char name[20]; /*姓名*/int score; /*成績*/struct stud_node *next; /*指向下個結點的指針*/ };單向鏈表的頭尾指針保存在全局變量head和tail中。
輸入為若干個學生的信息(學號、姓名、成績),當輸入學號為0時結束。
裁判測試程序樣例:
輸入樣例:
1 zhang 78 2 wang 80 3 li 75 4 zhao 85 0輸出樣例:
1 zhang 78 2 wang 80 3 li 75 4 zhao 85 typedef struct stud_node *ptr; void input() {ptr t=(ptr)malloc(sizeof(struct stud_node));scanf("%d",&t->num);while(t->num!=0){scanf("%s%d",&t->name,&t->score);if(tail==NULL){head=t;head->next=NULL;}else{tail->next=t; }tail=t;tail->next=NULL;t=(ptr)malloc(sizeof(struct stud_node));scanf("%d",&t->num);} }總結
以上是生活随笔為你收集整理的6-4 建立学生信息链表 (20 分)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Darwin操作系统简介
- 下一篇: 数据结构:链表(c语言)