77范文网 - 专业文章范例文档资料分享平台

数据结构与算法 查找与排序(3)

来源:网络收集 时间:2018-12-21 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

node * dest = NULL;

//找到某一英语成绩所对应的记录的BST节点的父节点 void searParent(BST t, keytype a) {

if(t == NULL) {

parent = NULL; }

else if(a == t ->data.key) {

dest = t; return; } else {

parent = t;

if(a < t->data.key) {

searParent(t->lchild, a); } else {

searParent(t->rchild, a); } } }

//删除以英语成绩为关键字的BST中英语成绩为a的记录 BST dele(BST t, keytype a) {

node * tmp; node * tmp2;

searParent(t, a); if(t == NULL) {

printf(\找不到要删除的记录!\\n\ return t; }

else if( t ->lchild == NULL && t->rchild == NULL) {

free(t);

return NULL; }

else if(parent == NULL)

{

printf(\找不到要删除的记录!\\n\ return t; } else {

if(dest->lchild == NULL && dest ->rchild == NULL) {

tmp = dest;

if(parent ->lchild == dest) {

parent ->lchild =NULL; } else {

parent ->rchild = NULL; }

free(tmp); }

else if(dest ->lchild == NULL) {

tmp = dest; if(dest != t) {

if(parent ->lchild == dest) {

parent ->lchild = dest ->rchild; } else {

parent ->rchild = dest ->rchild; } } else {

t = t ->rchild; }

free(tmp); }

else if(dest -> rchild == NULL) {

tmp = dest; if(dest != t) {

if(parent ->lchild == dest) {

parent ->lchild = dest ->lchild; } else {

t = dest ->lchild; } } else {

t = t ->lchild; }

free(tmp); } else {

tmp2 = dest; parent = dest;

tmp2 = tmp2 -> rchild;

while(tmp2 -> lchild != NULL) {

parent = tmp2;

tmp2 = tmp2 -> lchild; }

dest -> data = tmp2 ->data; if(parent == dest) {

parent ->rchild = tmp2 ->rchild; } else {

parent -> lchild = tmp2-> rchild; }

free(tmp2); }

return t; } }

//根据关键字为记录集排序并输出到屏幕(降序) void sort_output(BST t) {

if(t!= NULL) {

sort_output(t->rchild);

printf(\ printf(\英语:%.1f \ printf(\计算机:%.1f \ printf(\数学:%.1f \ printf(\学分绩:%.1f\\n\ sort_output(t->lchild); } }

//分别建立以英语成绩为关键字的BST和以学分绩为关键字的BST void build2(BST * t, BST * t2) {

record a;

printf(\请依次输入n个记录的姓名 英语成绩 计算机成绩 数学成绩 -1 -1 -1 -1表示结束:\\n\ scanf(\

scanf(\

a.GPA = (a.EN*1.5 + a.CS * 3.5 + a.MATHS * 5)/10; while(a.key!= -1) {

(*t) = inser((*t),a); (*t2) = inser2((*t2), a); scanf(\

scanf(\

a.GPA = (a.EN*1.5 + a.CS * 3.5 + a.MATHS * 5)/10; } }

//在以学分绩为关键字的BST上插入一条记录 BST inser2(BST t, record a) {

if(t == NULL) {

t = malloc(sizeof(node)); t->data= a;

t->lchild = NULL; t->rchild = NULL; } else {

if(a.key2 > t->data.key2)

{

t -> rchild = inser2(t->rchild, a); } else {

if(a.key2 < t->data.key2) {

t ->lchild = inser2(t->lchild, a); } } }

return t; }

//根据学分绩在以学分绩为关键字的BST上查找记录 record sear2(BST t, keytype a) {

record re; re.GPA = -1; if(t == NULL) {

printf(\不存在该关键字所对应的记录!\\n\ return re; }

if(t ->data.key2 == a) {

return t->data; } else {

if(t->data.key2 < a) {

return sear2(t ->rchild, a); } else {

return sear2(t -> lchild, a); } } }

//在以学分绩为关键字的BST上查找学分绩为a的记录对应的结点的父节点 void searParent2(BST t, keytype a) {

if(t == NULL)

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库数据结构与算法 查找与排序(3)在线全文阅读。

数据结构与算法 查找与排序(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/380527.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: