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

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

鏈表初識

2019-11-08 02:16:07
字體:
來源:轉載
供稿:網友
//鏈表#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;}}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 广东省| 津市市| 确山县| 贵溪市| 大邑县| 上林县| 合作市| 旬阳县| 盐池县| 三原县| 阿瓦提县| 台北市| 定兴县| 中超| 呈贡县| 房产| 万州区| 宁都县| 尖扎县| 南陵县| 读书| 汉沽区| 汝城县| 富裕县| 祁阳县| 锦屏县| 丰县| 县级市| 忻州市| 寿光市| 和政县| 白朗县| 镇沅| 辽宁省| 文山县| 仪陇县| 武鸣县| 九龙县| 太仆寺旗| 阳泉市| 佛冈县|