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

📄 binarysearchtree.cpp

📁 二叉树
💻 CPP
字号:
//实现二叉搜索树的类定义、插入、删除、查找操作
//实现平衡树的检查,并且想要实现完全平衡树的检查,不好实现啊,还没实现

# include<iostream.h>
# include"BinarySearchTree.h"

void main()
{
	int i;
/*	BinarySearchTree<int> bst;
	
	bst.makeBST();
	cout<<"The in order of the new tree is:\n";
	bst.inOrder(bst.getRoot());
	cout<<endl;

	if(bst.isTreeBalanced(bst.getRoot()))
	{
		cout<<"The tree is balanced!\nNow,check whether the tree is completely balanced.\n";
		if(bst.isTreeCompletelyBalanced(bst.getRoot(),i))
			cout<<"The tree is completely balanced!\n";
		else
			cout<<"The tree is not completely balanced!\n";
	}
	else
		cout<<"The tree is unbalanced!\n";*/


	//传入有序的字母表数组,会造出来平衡的二叉搜索树,数组要是无序,则二叉树就不平衡
	BinarySearchTree<char> alphabet;
	char alpArrary[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\0'};

	cout<<alpArrary<<endl;
	alphabet.balance(alpArrary,0,25);
	cout<<endl;
	alphabet.inOrder(alphabet.getRoot());
	cout<<endl;
    if(alphabet.isTreeBalanced(alphabet.getRoot()))
	{
		cout<<"The tree is balanced!\nNow,check whether the tree is completely balanced.\n";
		if(alphabet.isTreeCompletelyBalanced(alphabet.getRoot(),i))
			cout<<"The tree is completely balanced!\n";
		else
			cout<<"The tree is not completely balanced!\n";
	}
	else
		cout<<"The tree is unbalanced!\n";

	// 二叉搜索树的类定义、插入、删除、查找操作
	/*int key;
	cout<<"\nNow,insert a key to the binary serch tree\n Please in put it\n";
	cin>>key;
    bst.insertBSTNode(key);
	cout<<"The in order of the tree after the insert.\n";
	bst.inOrder(bst.getRoot());
	cout<<endl;

	cout<<"Please input a key, the function will find it.\n";
	cin>>key;
	if(bst.findBSTNode(key))
		cout<<"Find it!\n";
	else
		cout<<"Can't find it.\n";

	cout<<"Please input a key, the function will find and delete it.\n";
	cin>>key;
	bst.findAndDelete(key);
	cout<<"After delete the key,the in order of the tree is:\n";
	bst.inOrder(bst.getRoot());
	cout<<endl;*/


}

⌨️ 快捷键说明

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