欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    平衡二叉树学生信息管理系统程序(共13页).doc

    • 资源ID:13981643       资源大小:38.50KB        全文页数:13页
    • 资源格式: DOC        下载积分:20金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要20金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    平衡二叉树学生信息管理系统程序(共13页).doc

    精选优质文档-倾情为你奉上#include<stdio.h>#include<string.h>typedef struct A char NO10; char name10; char birt10; char clas10; char sex2;Elemtype;typedef struct BElemtype data;int bf;struct B *lchild;struct B *rchild;node,*pnode;void left1(pnode &ptree,int &taller)pnode p1,p2;if(ptree->bf=0)ptree->bf=1;taller=1;else if (ptree->bf=-1)ptree->bf=0;taller=0;elsep1=ptree->lchild;if (p1->bf=1)ptree->lchild=p1->rchild;p1->rchild=ptree;ptree->bf=p1->bf=0;ptree=p1;else if (p1->bf=-1)p2=p1->rchild;p1->rchild=p2->lchild;p2->lchild=p1;ptree->lchild=p2->rchild;p2->rchild=ptree;if (p2->bf=0)ptree->bf=p1->bf=0;else if (p2->bf=1)p1->bf=0;ptree->bf=-1;elsep1->bf=1;ptree->bf=0;ptree=p2;ptree->bf=0;taller=0;void right1(pnode &ptree,int &taller)pnode p1,p2;if(ptree->bf=0)ptree->bf=-1;taller=1;else if (ptree->bf=1)ptree->bf=0;taller=0;elsep1=ptree->rchild;if (p1->bf=-1)ptree->rchild=p1->lchild;p1->lchild=ptree;ptree->bf=p1->bf=0;ptree=p1;else if (p1->bf=1)p2=p1->lchild;p1->lchild=p2->rchild;p2->rchild=p1;ptree->rchild=p2->lchild;p2->lchild=ptree;if (p2->bf=0)ptree->bf=p1->bf=0;else if (p2->bf=-1)p1->bf=0;ptree->bf=1;elsep1->bf=-1;ptree->bf=0;ptree=p2;ptree->bf=0;taller=0;int insert(pnode &ptree,Elemtype e,int &taller)if (ptree=NULL)ptree=new node;ptree->data=e;ptree->lchild=ptree->rchild=NULL;ptree->bf=0;taller=1;elseif (strcmp(e.NO,ptree->data.NO)=0)taller=0;return 0;if(strcmp(e.NO,ptree->data.NO)<0)if(insert(ptree->lchild,e,taller)=0)return 0;if(taller=1)left1(ptree,taller);elseif(insert(ptree->rchild,e,taller)=0)return 0;if(taller=1)right1(ptree,taller);return 1;void left2(pnode &ptree,int &taller)pnode p1,p2;if (ptree->bf=1)ptree->bf=0;taller=1;else if (ptree->bf=0)ptree->bf=-1;taller=0;elsep1=ptree->rchild;if(p1->bf=0)ptree->rchild=p1->lchild;p1->lchild=ptree;p1->bf=1;ptree->bf=-1;ptree=p1;taller=0;else if (p1->bf=-1)ptree->rchild=p1->lchild;p1->lchild=ptree;ptree->bf=p1->bf=0;ptree=p1;taller=1;elsep2=p1->lchild;p1->lchild=p2->rchild;p2->rchild=p1;ptree->rchild=p2->lchild;p2->lchild=ptree;if (p2->bf=0)ptree->bf=0;p1->bf=0;else if (p2->bf=-1)ptree->bf=1;p1->bf=0;elseptree->bf=0;p1->bf=-1;p2->bf=0;ptree=p2;taller=1;void right2(pnode &ptree,int &taller)pnode p1,p2;if (ptree->bf=-1)ptree->bf=0;taller=1;else if (ptree->bf=0)ptree->bf=1;taller=0;elsep1=ptree->lchild;if(p1->bf=0)ptree->lchild=p1->rchild;p1->rchild=ptree;p1->bf=-1;ptree->bf=1;ptree=p1;taller=0;else if (p1->bf=1)ptree->lchild=p1->rchild;p1->rchild=ptree;ptree->bf=p1->bf=0;ptree=p1;taller=1;elsep2=p1->rchild;p1->rchild=p2->lchild;p2->lchild=p1;ptree->lchild=p2->rchild;p2->rchild=ptree;if (p2->bf=0)ptree->bf=0;p1->bf=0;else if (p2->bf=1)ptree->bf=-1;p1->bf=0;elseptree->bf=0;p1->bf=1;p2->bf=0;ptree=p2;taller=1;void delete2(pnode q,pnode &r,int &taller)if (r->rchild=NULL)q->data=r->data;q=r;r=r->lchild;delete q;taller=1;elsedelete2(q,r->rchild,taller);if(taller=1)right2(r,taller);int delete1(pnode &ptree,char x10,int &taller)int k;pnode q;if(ptree=NULL)return 0;else if (strcmp(x,ptree->data.NO)<0)k=delete1(ptree->lchild,x,taller);if(taller=1)left2(ptree,taller);return k;else if (strcmp(x,ptree->data.NO)>0)k=delete1(ptree->rchild,x,taller);if(taller=1)right2(ptree,taller);return k;elseq=ptree;if (ptree->rchild=NULL)ptree=ptree->lchild;delete q;taller=1;else if (ptree->lchild=NULL)ptree=ptree->rchild;delete q;taller=1;elsedelete2(q,q->lchild,taller);if(taller=1)left2(q,taller);ptree=q;return 1;void create(pnode &ptree,int n)int j;Elemtype e;printf("输入学生信息:姓名,学号,生日,班级,性别n");for(int i=0;i<n;i+)scanf("%s%s%s%s%s",e.name,e.NO,e.birt,e.clas,e.sex);insert(ptree,e,j);void display(pnode ptree)if (ptree)display(ptree->lchild);printf("%-10s %-10s %-10s %-10s %-10sn",ptree->data.name,ptree->data.NO,ptree->data.birt,ptree->data.clas,ptree->data.sex);display(ptree->rchild);void find(pnode ptree,char *ch)if(ptree)if (strcmp(ptree->data.name,ch)=0)printf("姓名 学号 生日 班级 性别n");printf("%-10s %-10s %-10s %-10s %-10snn",ptree->data.name,ptree->data.NO,ptree->data.birt,ptree->data.clas,ptree->data.sex);return ;elsefind(ptree->lchild,ch);find(ptree->rchild,ch);void save(pnode ptree,FILE *p)if (ptree)save(ptree->lchild,p);p=fopen("student.txt","a");fprintf(p,"%st%st%st%st%sn",ptree->data.name,ptree->data.NO,ptree->data.birt,ptree->data.clas,ptree->data.sex);fclose(p);save(ptree->rchild,p);void read(pnode &ptree,FILE *p)int j;char c;Elemtype e;if(p=fopen("student.txt","r")=NULL)return ;while(c=fgetc(p)!=EOF)fscanf(p,"%s%s%s%s%s",e.name,e.NO,e.birt,e.clas,e.sex);insert(ptree,e,j);fclose(p);void Print(pnode ptree,int indent)if (ptree = NULL) return;for(int i = 0; i < indent; i+)printf("|- ");printf("%-10s %-10s %-10s %-10s %-10sn",ptree->data.name,ptree->data.NO,ptree->data.birt,ptree->data.clas,ptree->data.sex);Print(ptree->lchild, indent+1);Print(ptree->rchild, indent+1);void change(pnode ptree,Elemtype e)if (ptree=NULL)return ;elseif (strcmp(ptree->data.NO,e.NO)=0)ptree->data=e;return;elsechange(ptree->lchild,e);change(ptree->rchild,e);void male(pnode ptree)char m2="m"if (ptree)male(ptree->lchild);if(strcmp(ptree->data.sex,m)=0)printf("%-10s %-10s %-10s %-10s %-10sn",ptree->data.name,ptree->data.NO,ptree->data.birt,ptree->data.clas,ptree->data.sex);male(ptree->rchild);void fmale(pnode ptree)char m2="f"if (ptree)fmale(ptree->lchild);if(strcmp(ptree->data.sex,m)=0)printf("%-10s %-10s %-10s %-10s %-10sn",ptree->data.name,ptree->data.NO,ptree->data.birt,ptree->data.clas,ptree->data.sex);fmale(ptree->rchild);void main()int z; FILE *p=NULL;pnode ptree=NULL;printf("请选择:n1-载入学生信息n2-重新创建信息n"); scanf("%d",&z);if(z=1)read(ptree,p); Elemtype e,a;int t=1;char ch10,x10;int j,k,n;while (t)printf("* 平衡二叉树实现学生基本信息管理*n");printf("*nn");printf("1-创建n");printf("2-插入n");printf("3-删除n");printf("4-修改n");printf("5-查找n");printf("6-显示n");printf("7-排序n"); printf("8-分组n");printf("9-保存n");printf("0-退出n");printf("输入操作选项(0-9)n");scanf("%d",&k);switch (k) case 1:printf("输入要创建的学生数n");scanf("%d",&n);create(ptree,n);break; case 2:printf("输入学生信息: 姓名,学号,生日,班级,性别n");scanf("%s%s%s%s%s",e.name,e.NO,e.birt,e.clas,e.sex);insert(ptree,e,j);break;case 3:printf("输入要删除的学生的学号n");scanf("%s",x);delete1(ptree,x,j);break;case 4:printf("输入修改后的信息: 姓名,学号,生日,班级,性别n");scanf("%s%s%s%s%s",a.name,a.NO,a.birt,a.clas,a.sex);change(ptree,a); break;case 5:printf("输入要查找的学生姓名n");scanf("%s",ch);find(ptree,ch);printf("n");break;case 6: printf("凹入显示:nn");Print(ptree,0);printf("n");break;case 7:printf("按学号排序结果如下:nn"); printf("姓名 学号 生日 班级 性别n");display(ptree);printf("n");break;case 8:printf("男生基本信息如下:nn");male(ptree);printf("n");printf("女生基本信息如下:nn");fmale(ptree);printf("n");break;case 9:p=fopen("student.txt","wt");fprintf(p,"n");fclose(p);save(ptree,p);printf("学生信息已存入文件nn");break;case 0:printf("谢谢使用,再见n");t=0;break;专心-专注-专业

    注意事项

    本文(平衡二叉树学生信息管理系统程序(共13页).doc)为本站会员(飞****2)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开