#include "Assistance.h" // 辅助软件包
#include "BinarySortTree.h" // 二叉排序树类
int main(void)
{
BinarySortTree<int> bt;
//int elem[] = { 39, 68, 11, 23, 46, 34, 75, 86, 8, 71 };
int elem[] = { 23,9,87,94,53,17,65,81,78,72};
int n = 10;
for (int i = 0; i < n; i++)
bt.Insert(elem[i]); // 根据elem数组中的元素构造二叉排序树
cout << "原二叉排序树:" << endl;
DisplayBTWithTreeShape(bt);
cout << endl;
system("PAUSE");
char c = 'x';
int x;
while (c != '0') {
cout << endl << "1. 插入元素.";
cout << endl << "2. 删除元素.";
cout << endl << "3. 中序遍历.";
cout << endl << "4. 显示二叉排序树.";
cout << endl << "0. 退出";
cout << endl << "选择功能(0~4):";
cin >> c;
switch (c) {
case '1':
cout << endl << "输入插入元素的值:";
cin >> x;
bt.Insert(x);
break;
case '2':
cout << endl << "输入删除元素的值:";
cin >> x;
bt.Delete(x);
break;
case '3':
cout << endl;
bt.InOrder(Write<int>);
break;
case '4':
cout << endl;
DisplayBTWithTreeShape(bt);
break;
}
}
system("PAUSE");
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
为了向二叉排序树中插入一个新元素,必须先检查这个元素在二叉排序树中是否已经存在。因此,在插入之前,首先在二叉排序树中检查待插入的数据元素,如果查找成功,说明树中已经存在这个数据元素,则不再插入:如果查找不成功,说明树中不存在关键字等于给定值的数据元素。 在二叉排序树中删除一个数据元素时,必须将因删除元素而断开的二叉链表重新链接起来,同时确保不会失去二叉排序树的性质。此外,为了保证在执行删除后二叉排序树的查找性能不降低,还需要做到重新链接后二叉排序树的高度不增加。所有这些因素都应当在删除算法中得到体现。
资源推荐
资源详情
资源评论
收起资源包目录
BinarySortTree.rar (29个子文件)
BinarySortTree
.vs
BinarySortTree
v17
Browse.VC.db 15.72MB
.suo 57KB
ipch
AutoPCH
c863204e4bb8dabd
4675e1f9106a1d23
bd0a096fc9e2ee5d
TESTBINARYSORTTREE.ipch 39.13MB
1cba2a00b431c64a
TEST.ipch 39.63MB
18e7e6ca61e5c814
f6c4f3f48139314a
TEST.ipch 39.63MB
18d6ed52ea209252
3af7143940c68862
BINARYSORTTREE.ipch 640KB
579cd97e698aad17
12f3ccc2c5411f5c
fc34b216491c69f
7e48b4957219fca6
x64
Debug
BinarySortTree.pdb 2.4MB
BinarySortTree.exe 86KB
BinarySortTree.sln 1KB
BinarySortTree
Assistance.h 3KB
BinarySortTree.h 7KB
x64
Debug
vc143.pdb 484KB
test.obj 139KB
BinarySortTree.tlog
CL.write.1.tlog 1KB
CL.command.1.tlog 2KB
link.command.1.tlog 4KB
link.read.1.tlog 3KB
link.write.1.tlog 1KB
BinarySortTree.lastbuildstate 243B
CL.read.1.tlog 15KB
BinarySortTree.exe.recipe 385B
BinarySortTree.ilk 805KB
BinarySortTree.log 175B
vc143.idb 291KB
BinarySortTree.vcxproj.user 168B
BinTreeNode.h 764B
test.cpp 1KB
BinarySortTree.vcxproj.filters 1KB
BinarySortTree.vcxproj 7KB
共 29 条
- 1
资源评论
tbznl
- 粉丝: 147
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功