温温酱
完整程序#include<stdio.h>#include<string.h>#include<malloc.h>#include<stdlib.h>int n,m,i,t,q1=1;int e=1,counter=0,counter1=0,counter2=0;struct student{char name[20];int num;int classname;int math;int english;int chinese;};typedef student DataType;/**********链表定义**********/typedef struct Node{DataType data;struct Node *next;}SLNode;SLNode *head,*q,s1;/**********数学二叉树定义***********/typedef struct node{DataType data;struct node*leftChild;struct node*rightChild;}BiTreenode;BiTreenode *root,*v,*u,*o,*q4,*q2,*q3;void Initiate(BiTreenode**root){*root=(BiTreenode*)malloc(sizeof(BiTreenode));(*root)->leftChild=NULL;(*root)->rightChild=NULL;}/**************英语初始化函数*****************/void initiate(BiTreenode**eoot){*eoot=(BiTreenode*)malloc(sizeof(BiTreenode));(*eoot)->leftChild=NULL;(*eoot)->rightChild=NULL;}BiTreenode *eoot,*a,*b,*c;char s[]=;/*****************初始化**********************/void ListInitiate(SLNode **head ){if((*head=(SLNode*)malloc(sizeof(SLNode)))==NULL) exit(1);(*head)->next=NULL;}/****************求当前数据元素个数***********/int ListLength(SLNode *head){SLNode *p=head;int size=0;while(p->next!=NULL){p=p->next;size++;}return size;}/**************插入数据元素****************/int ListInsert(SLNode *head,int i,DataType x){SLNode *p,*q;int j;p=head;j=-1;while(p->next!=NULL&&j<i-1){p=p->next;j++;}if(j!=i-1){printf("插入位置参数错误!\n");return 0;}if((q=(SLNode *)malloc(sizeof(SLNode)))==NULL) exit(1);q->data=x;q->next=p->next;p->next=q;return 1;}/****************删除数据元素****************/int ListDelete(SLNode *head,int i,DataType *x){SLNode *p,*s;int j;p=head;j=-1;while(p->next!=NULL&&j<i-1&&p->next->next!=NULL){p=p->next;j++;}if(j!=i-1){printf("删除位置参数错误!\n");return 0;}s=p->next;*x=s->data;p->next=p->next->next;free(s);return 1;}/***************取数据元素*****************/int ListGet(SLNode *head,int i,DataType *x){SLNode *p;int j;p=head;j=-1;while(p->next!=NULL&&j<i){p=p->next;j++;}if(j!=i){printf("取元素位置参数错误!\n");return 0;}*x=p->data;return 1;}/************撤消单链表**************/void Destroy(SLNode * *head){SLNode *p,*p1;p=*head;while(p!=NULL){p1=p;p=p->next;free(p1);}*head=NULL;}/***********数学寻树函数****************/void Sxunshu(BiTreenode *v,SLNode *p){if(p->next->data.math>v->leftChild->data.math){if(v->leftChild->leftChild!=NULL){v=v->leftChild;Sxunshu(v,p);}else{v->leftChild->leftChild=o;v->leftChild->leftChild->rightChild=NULL;v->leftChild->leftChild->leftChild=NULL;}}else{if(v->leftChild->rightChild!=NULL){v=v->rightChild;Sxunshu(v,p);}else{v->leftChild->rightChild=o;v->leftChild->rightChild->rightChild=NULL;v->leftChild->rightChild->leftChild=NULL;}}}/*************英语寻树函数**************/void Exunshu(BiTreenode *a,SLNode *p){if(p->next->data.english>a->leftChild->data.english){if(a->leftChild->leftChild!=NULL){a=a->leftChild;Exunshu(a,p);}else{a->leftChild->leftChild=c;a->leftChild->leftChild->rightChild=NULL;a->leftChild->leftChild->leftChild=NULL;}}else{if(a->leftChild->rightChild!=NULL){a=a->rightChild;Exunshu(a,p);}else{a->leftChild->rightChild=c;a->leftChild->rightChild->rightChild=NULL;a->leftChild->rightChild->leftChild=NULL;}}}/*************英语成绩录入**************/void englishy(){SLNode *p;initiate(&eoot);b=eoot;p=head;printf("共有%d位同学成绩输入",counter2);do{c=(BiTreenode*)malloc(sizeof(BiTreenode));strcpy(s,p->next->data.name);puts(s);scanf("%d",&t);p->next->data.english=t;strcpy(c->data.name,p->next->data.name);c->data.english=p->next->data.english;a=eoot;if(b==eoot){b->leftChild=c;b=b->leftChild;b->leftChild=NULL;b->rightChild=NULL;}else Exunshu(a,p);p=p->next;counter2--;}while(p->next!=NULL);printf("英语成绩录入完毕");}/**********数学成绩录入**********/void mathy(){SLNode *p;Initiate(&root);u=root;p=head;printf("共有%d位同学成绩输入",counter1);do{o=(BiTreenode*)malloc(sizeof(BiTreenode));strcpy(s,p->next->data.name);puts(s);scanf("%d",&t);p->next->data.math=t;strcpy(o->data.name,p->next->data.name);o->data.math=p->next->data.math;v=root;if(u==root){u->leftChild=o;u=u->leftChild;u->leftChild=NULL;u->rightChild=NULL;}else Sxunshu(v,p);p=p->next;counter1--;}while(p->next!=NULL);printf("数学成绩录入完毕");}/*****************注册函数********************/int zhuce(){ SLNode *p;q=head;int j,z=0;j=-1;while(q->next!=NULL&&j<z-1){q=q->next;j++;}if(j!=z-1){printf("插入位置参数错误!\n");return 0;}printf("请输入注册学生数目");scanf("%d",&m);for(i=0;i<m;i++){if((p=(SLNode *)malloc(sizeof(SLNode)))==NULL) exit(1);q->next=p;q=q->next;q->next=NULL;printf("请输入第%d学生姓名\n",i+1);scanf("%s",s);strcpy(q->data.name,s);printf("请输入该学生班级\n");scanf("%d",&q->data.classname);printf("请输入该学生学号\n");scanf("%d",&q->data.num);printf("注册成功!\n");counter++;counter1++;counter2++;}printf("\t\n注册已完毕!\n");if(counter1==0)counter1=counter;if(counter2==0)counter2=counter;return 1;}/***********学生删除函数****************/void zengjia(){while(e==1){printf("请输入您要删除的学生姓名\n");scanf("%s",s);SLNode *p,*r;p=head;r=p;while(p->next!=NULL&&strcmp(p->next->data.name,s)){r=p;p=p->next;}if(p->next==NULL)printf("删除失败");else{r->next=p->next->next;p=r->next;printf("已删除!\n\t1.继续删除\t\t2.返回\n");printf("请选择[ ]\b\b");scanf("%d",&e);}}e=1;counter--;counter1--;counter2--;}/*******************成绩录入函数********************/int chengjiluru(){printf("请选择需要录入的学科\n");printf("1.math\t2.english\n\t[ ]\b\b");scanf("%d",&t);switch(t){case 1:mathy();break;case 2:englishy();break;}return 1;}/************数学后续遍历函数*******************/void postorder(BiTreenode*q2){if(q2!=NULL){ postorder(q2->leftChild);postorder(q2->rightChild);if(!strcmp(q2->data.name,s))q2->data.math=n;}}/************数学成绩修改****************/void chengjixiugai(){SLNode *h,*f;q2=root->leftChild;h=head;f=h;printf("输入成绩错误的的科目是:\n1.math\t2.english\n []\b\b");scanf("%d",&t);printf("成绩需要修改的学生名字是\n");scanf("%s",s);while(strcmp(h->next->data.name,s)){if(h->next->next==NULL)break;else h=h->next;}if(h->next->next==NULL)printf("没有此学生");else{if(t==1){printf("请再次输入成绩");scanf("%d",&n);h->next->data.math=n;postorder(q2);printf("成绩修改完毕");}}}int shuru(){printf("\t\t\t欢迎光临学生成绩管理系统\n\n\n");printf("功能如下:");printf("\t1。学生注册登记\n\t2。删除学生\n\t3。成绩录入\n\t4。成绩修改\n\t5。统计分析\n\t6。查找\n\t7。打印\n");printf("请选择您需要的功能[ ]\b\b");scanf("%d",&n);switch(n){case 1:zhuce();break;case 2:zengjia();break;case 3:chengjiluru();break;case 4:chengjixiugai();break;//se 5:tongjifenxi();//se 6:chazhao();//se 7:dayin();}return 1;}void main(){ ListInitiate(&head);q=head;while(1){shuru();}}