1.编写函数,建立有序表,采用折半查找实现某一已知的关键字的查找(采用顺序表存储结构)
2.编写函数,随机产生一组关键字,利用二叉排序树的插入算法建立二叉排序树
3.编写函数,在以上二叉排序树中删除某一指定关键字元素
4.编写一个主函数,在主函数中设计一个简单的菜单,分别调试上述算法
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
int a[100];
void erfen(int n, int x)
{
int l = 0, r = n - 1, mid;
while (l <= r)
{
mid = (l + r) / 2;
if (a[mid] == x)
{
cout << x << "在第" << mid + 1 << "个位置" << endl;
return;
}
else if (a[mid]>x)
r = mid - 1;
else l = mid + 1;
}
cout << "未能找到" << x << endl;
}
struct node
{
int key;
node *l, *r;
};
node* InsertBST(node *T, int key)///二叉排序树插入节点
{
node *f = T, *p = T;
while (p)
{
if (p->key == key) return T;
f = p;//用f记下查找路径上的最后一个访问的节点
p = (key<p->key) ? p->l : p->r;
}
p = (nod