1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > (四川大学出版社C语言程序设计第二版课后习题)学生信息:学号 成绩 读出形成链表

(四川大学出版社C语言程序设计第二版课后习题)学生信息:学号 成绩 读出形成链表

时间:2019-12-12 00:04:34

相关推荐

(四川大学出版社C语言程序设计第二版课后习题)学生信息:学号 成绩 读出形成链表

#include<stdio.h>#include<stdlib.h>#include<string.h>#define P 3//学生人数#define LEN sizeof(struct Student) //结构体长度,方便后面为其分配空间struct Student *Create(); //创建链表void Print(struct Student *head); //输出链表void Fang(struct Student **head); //释放链表void Seek(struct Student *head);//查找替换struct Student{char xh[12];float cj;struct Student *next;};int main(){struct Student *head;head=Create();Seek(head);printf("替换成绩后学生信息如下:\n");Print(head);Fang(&head);return 0;}struct Student *Create(){struct Student *head=NULL,*p,*p1;;int i=0;while(i<P){p=(struct Student *)malloc(LEN);printf("请输入第%d位同学的学号,成绩,以空格间隔:\n",i+1);scanf("%s%f",p->xh ,&p->cj );p->next =NULL;i++;if(head==NULL){head=p;p1=p;}else{p1->next=p;p1=p;}}return head;}void Print(struct Student *head){struct Student *p;p=head;while(p!=NULL){printf("%s,%.1f\n",p->xh ,p->cj );p=p->next ;}}void Fang(struct Student **head){struct Student *p;while(*head!=NULL){p=*head;*head=(*head)->next ;free(p);}*head=NULL;}void Seek(struct Student *head){struct Student *p;p=head;char x[12];float c;printf("请输入要替换成绩的同学的学号:\n");scanf("%s",x);while(p!=NULL){if(strcmp(p->xh,x)==0){printf("请输入要替换的成绩:\n");scanf("%f",&c);p->cj =c;break;}elsep=p->next; }}

(四川大学出版社C语言程序设计第二版课后习题)学生信息:学号 成绩 读出形成链表 查找某个学号的学生 将其成绩替换成新的成绩

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。