We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#include<stdio.h> #include<stdlib.h> struct student { char name[20]; int num; int age; char sex[20]; int snum; int cnum; struct student *next; }; struct student *creat()//创建链表 { struct student *head=NULL; struct student *cut,*end; end=cut=(struct student *)malloc(sizeof(struct student)); scanf("%s %d %d %s %d %d",cut->name,&cut->num,&cut->age,cut->sex,&cut->snum,&cut->cnum); while(cut->num>0) { if(head==NULL) head=cut; else { end->next=cut; end=cut; cut=(struct student*)malloc(sizeof(struct student)); scanf("%s %d %d %s %d %d",cut->name,&cut->num,&cut->age,cut->sex,&cut->snum,&cut->cnum); } } end->next=NULL; return(head); } void print(struct student*head)//输出链表 { struct student *a; a=head; if(a==NULL) { printf("这是空的"); exit(1); } else while(a!=0) { printf("%s %d %d %s %d %d\n",a->name,a->num,a->age,a->sex,a->snum,a->cnum); a=a->next; } } void chaxun(struct student*head,int num)//查询 { struct student *a; a=head; while(a!=NULL) { if(num==a->num) printf("%s %d %d %s %d %d",a->name,a->num,a->age,a->sex,a->snum,a->cnum); break; } } struct student *del(struct student*head,int num)//删除 { struct student *a,*cut,*end; a=head; while(num!=a->num&&a->next!=NULL) { end=a; a=a->next; } if(a->num!=num) printf("无该学生信息"); else { if(a==head) head=a->next; else { end->next=a->next; } } return(head); } struct student *charu(struct student *head,struct student *jing,int num)//插入 { struct student *a,*cut,*end,*xin; a=head; xin=jing; while(num!=a->num&&a->next!=NULL) { cut=a; a=a->next; } if(num!=a->num) printf("无法插入到指定位置"); else if(a==head) { head->next=xin; } else if(a->next=NULL) { a->next=xin; xin->next=NULL; } else { end=a->next; a->next=xin; xin->next=end; } return(head); } void save(struct student*head) //保存数据到文件 { struct student *a; a=head; FILE*fp; if((fp=fopen("D:\student.dat","wb"))==NULL) { printf("cannot open the file"); exit(0); } while(a!=NULL) { fprintf(fp,"%s %d %d %s %d %d",a->name,a->num,a->age,a->sex,a->snum,a->cnum); a=a->next; } } int main() { struct student *head,*shan,*jin,*jing; int m,n,k; head=creat(); printf("输出所有信息:\n"); print(head); printf("请输入查询学生的学号:\n"); scanf("%d",&m); printf("该学生的信息为:\n"); chaxun(head,m); printf("请输入要删除信息的学生的学号:\n"); scanf("%d",&n); shan=del(head,n); printf("输出剩余学生信息:\n"); print(shan); printf("请输入新增学生的信息:\n"); jing=(struct student *)malloc(sizeof(struct student)); jing->next=NULL; scanf("%s %d %d %s %d %d",jing->name,&jing->num,&jing->age,jing->sex,&jing->snum,&jing->cnum); printf("请输入A学生的学号(新增学生的信息在A学生之后)(新增学生的位置):\n"); scanf("%d",&k); jin=charu(head,jing,k); printf("输出新增学生后的所有学生的信息:\n"); print(jin); system("pause"); save(head); return 0; }
The text was updated successfully, but these errors were encountered:
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: