#include#include #include #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 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,%.1fn",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; } else p=p->next; } }



