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

📄 main.cpp

📁 清华大学计算机系数据结构课程教材《数据结构 用面向对象方法和C++描述》(殷人昆主编)的类库(书中程序的源代码)
💻 CPP
字号:
#include<iostream>
#include"AVLTree.h";
using namespace std;

template<class E, class K>
struct Ele{
	K key;
	E e;
	Ele(K k=0 , E ee=0):key(k),e(ee){}
	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(){
	AVLTree<Ele<int ,int>, int> avl(-1); //以-1结束
	cin>>avl;
	cout<<avl;
	Ele <int, int> e(89);
	int temp;
	cout<<"树的高度:"<<avl.Height()<<endl;
    cout<<"输入要插入的元素:";
	cin>>e;
	avl.Insert(e);
	cout<<avl<<endl;
	
    cout<<"输入要删除的元素:";
	cin>>temp;
	if (avl.Remove(temp,e))
		cout<<avl<<endl;
	else
		cout<<"不存在"<<endl;
    cout<<"输入要搜索的元素:";
	cin>>temp;
	if (avl.Search(temp))
		cout<< temp <<" 存在"<<endl;
	else
		cout<<temp<<" 不存在"<<endl;
		cout<<"测试完毕"<<endl;

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

/*
输入示例:
AVL树:输入数据,以-1结束:
1
输入数据: 2
输入数据: 3
输入数据: 4
输入数据: 4
输入数据: 5
输入数据: 3
输入数据: -1
AVL树的中序遍历:
1 2 3 4 5
树的高度:3
输入要插入的元素:7
AVL树的中序遍历:
1 2 3 4 5 7

输入要删除的元素:2
AVL树的中序遍历:
1 3 4 5 7

输入要搜索的元素:3
3 存在
测试完毕

*/

⌨️ 快捷键说明

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