main.cpp

来自「二岔搜索树 可完成基本操作 遍历 查找 删除 判断两树是否相等」· C++ 代码 · 共 52 行

CPP
52
字号
#include "bst.h"

int main()
{
	BST<int> bst1;

	int a[8] = {23, 45, 12, 9, 123, 87, 22, 9};
	for (int i = 0; i < 8; i++) {
		bst1.insert(a[i]);
	}

	cout << bst1.max() << endl;
	cout << bst1.min() << endl;

	int b = 145;
	if (bst1.find(b))
		cout << "successful" << endl;
	else
		cout << "cannot find " << b << endl;

	bst1.remove(b);
	
	BSTNode<int> *root = bst1.getRoot();
	if (root)
		cout << root->getData() << endl;

	
	BSTNode<int> *temp = bst1.leftChild(bst1.getRoot());
	if (temp)
		cout << temp->getData() << endl;	
	
	temp = bst1.parent(bst1.leftChild(bst1.leftChild(bst1.getRoot())));
	if (temp)
		cout << temp->getData() << endl;		


	bst1.inOrder();
	cout << endl;

	cout << bst1.size() << endl;

	cout << endl << bst1.depth() << endl << endl;

	BST<int> bst2 = bst1;

	if (bst2 == bst1)
		cout << "equal" << endl;
	else
		cout << "not equal" << endl;

	return 0;
}

⌨️ 快捷键说明

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