平衡二叉树学生信息管理系统程序(共13页).doc
《平衡二叉树学生信息管理系统程序(共13页).doc》由会员分享,可在线阅读,更多相关《平衡二叉树学生信息管理系统程序(共13页).doc(13页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上#include#includetypedef 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
2、)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;p
3、tree-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
4、=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=NU
5、LL;ptree-bf=0;taller=1;elseif (strcmp(e.NO,ptree-data.NO)=0)taller=0;return 0;if(strcmp(e.NO,ptree-data.NO)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 p
6、1,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
7、-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-b
8、f=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
9、;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(pno
10、de &ptree,char x10,int &taller)int k;pnode q;if(ptree=NULL)return 0;else if (strcmp(x,ptree-data.NO)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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 平衡 二叉 学生 信息管理 系统 程序 13
限制150内