Beispiel #1
0
void main()
{
	Btree A;
	int array1[] = { 7, 4, 2, 3, 15, 35, 6, 45, 55, 20, 1, 14, 56, 57, 58 };
	int array[] = { 1, 2 };
	int k;
	k = sizeof(array) / sizeof(array[0]);
	cout << "建立排序二叉树顺序: " << endl;
	for (int i = 0; i<k; i++)
	{
		cout << array[i] << " ";
		A.create_Btree(array[i]);
	}
	cout << endl;
	cout << "二叉树节点个数: " << A.count(A.root) << endl;
	cout << "二叉树叶子个数:" << A.findleaf(A.root) << endl;
	cout << "二叉树中度数为1的结点的数量为:" << A.findnode(A.root) << endl;
	cout << endl << "先序遍历序列: " << endl;
	A.display1();
	cout << endl << "中序遍历序列: " << endl;
	A.display2();
	cout << endl << "后序遍历序列: " << endl;
	A.display3();
	cout << endl << "平衡树判断测试:" << endl;
	A.display4();


	system("PAUSE");
}
void menu()
{
	Btree <int> test;
	char choice;
	do
	{
		cout << endl;
		cout << "(C)ount"  << endl;
		cout << "(I)nsert" << endl;
		cout << "(R)emove" << endl;
		cout << "(P)rint " << endl;
		cout << "(Q)uit"   << endl;
		cout << "(S)earch" << endl;

		cin >> choice;
		switch (choice)
		{
		case 'C':
		case 'c':	{
					test.count();
					}


		case  'I':
		case  'i':   {
			int value;
			cout << "Give me a value and I will insert it " << endl;
			cin >> value;
			test.Insert(value);
			break;
		}

		case 'P':
		case 'p':   {
			test.preprint();
			break;

		}

		case 'R':
		case 'r':   {
			int value;
			cout << "Give me a value and I will remove it " << endl;
			cin >> value;
			test.Remove(value);
			break;
		}
		case 'q':
		case 'Q':
		{
			cout << "Bye Bye" << endl;
			return;
		}

		case 's':
		case 'S':
		{
			int value;
			cout << "Give me a value and I will search for it " << endl;
			cin >> value;
			if (test.Search(value))
				cout << "It was found in the binary tree!" << endl;
			else
				cout << "It was not found in the binary tree." << endl;
			break;
		}

		default: cout << "Bad user, enter a proper choice." << endl;


		}
	} while (1);
}