⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 清华大学计算机系数据结构课程教材《数据结构 用面向对象方法和C++描述》(殷人昆主编)的类库(书中程序的源代码)
💻 CPP
字号:
#include<iostream>
#include"BST.h"
using namespace std;
template<class E, class K>
struct Ele{
	K key;
	E e;
	friend istream & operator >> (istream& in, Ele<E,K>& temp ){
		in>>temp.key;
		return in;
	}
	friend ostream & operator << (ostream& out, Ele<E,K>& temp ){
		out<<temp.key;
		return out;
	}
	bool operator <(const Ele<E,K>& temp){
		return key<temp.key;
	}
	bool operator >(const Ele<E,K>& temp){
		return key>temp.key;
	}
	bool operator ==(const Ele<E,K>& temp){
		return key==temp.key;
	}
	Ele<E, K>& operator = (const Ele<E,K>& temp){
		key=temp.key;
		e=temp.e;
		return *this;
	}

};

int main(){
	cout<<"输入,以-1为结束"<<endl;
	BST <Ele<int ,int>,int> bst(-1);
	bst.PrintTree();
	cout<<endl;
	int s;
	cout<<"搜索元素:";
	cin>>s;
	if (bst.Search(s))
		cout<<"在表中"<<endl;
	BST <Ele<int ,int>,int> temp;
	temp= bst;
	temp.PrintTree();
	cout<<endl;
	cout<<"最大元素:"<<temp.Max()<<endl;
	cout<<endl;
	cout<<"最小元素:"<<temp.Min()<<endl;
	cout<<endl;
	temp.makeEmpty();
	if (temp.isEmpty())
		cout<<"置空后,为空"<<endl;
	cout<<endl;
	cout<<"删除元素:";
	cin>>s;
	bst.Remove(s);
	cout<<"删除后:"<<endl;
	if (bst.Search(s))
		cout<<"此元素存在"<<endl;
	else
		cout<<"此元素不存在"<<endl;
	cout<<endl;
	cout<<"测试完毕"<<endl;

	while(1)//为了在类库说明文档中便于观察,加入这一句
		cout<<"";
	return 0;
}

/*
输入示例:

输入,以-1为结束
请输入数据:
1
2
3
4
18
20
12
-1
1   2   3   4   12   18   20
搜索元素:2
在表中
20
最大元素:20

最小元素:20

置空后,为空

删除元素:12
删除后:
此元素不存在

测试完毕

*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -