国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

鏈表初識

2019-11-08 02:29:10
字體:
來源:轉載
供稿:網友
//鏈表#include<stdio.h>#include<string.h>#include<malloc.h>typedef struct Student{int id;char name[20];int score;struct Student *next;}Stud,*Stu;//head是一個帶頭節點的鏈表void insert(Stu head);void del(Stu head,int id);void PRint(Stu head);int main(){Stu s1=(Stu)malloc(sizeof(Stud));//頭指針s1->next=NULL;s1->id=0;//借用來表示鏈表的節點個數for(int i=0;i<3;i++) insert(s1);print(s1);printf("請輸入要刪除的學生學號:");int id;scanf("%d",&id);del(s1,id);print(s1);return 0;}void insert(Stu head){printf("請輸入學號 姓名 成績:");Stu q=(Stu)malloc(sizeof(Stud));scanf("%d %s %d",&q->id,q->name,&q->score);q->next=head->next;head->next=q;head->id++;}//head是一個帶頭節點的鏈表,id是要刪除節點的學號void del(Stu head,int id){Stu p=head;while(p->next!=NULL){if (p->id==id){Stu q=head->next;head->next=p->next;free(q);break;}else if(p->next->id==id){Stu q=p->next;p->next=p->next->next;free(q);head->id--;break;}p=p->next;}}//輸出鏈表數據void print(Stu head){Stu p=head;printf("鏈表共有%d個節點/n",head->id);while(p->next!=NULL){printf("學號%d,姓名%s,成績%d/n",p->next->id,p->next->name,p->next->score);p=p->next;}}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 克拉玛依市| 宾阳县| 云和县| 南华县| 清涧县| 望江县| 林口县| 梓潼县| 朝阳县| 双城市| 满城县| 夏邑县| 双牌县| 菏泽市| 普兰县| 铜山县| 清远市| 宜城市| 将乐县| 石阡县| 深泽县| 新津县| 甘泉县| 尉氏县| 乐清市| 金秀| 集贤县| 三明市| 漳平市| 宜宾县| 奇台县| 沙坪坝区| 克山县| 濮阳市| 铜鼓县| 金秀| 绍兴县| 当阳市| 大埔县| 新化县| 博客|