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

📄 binary_tree.cpp

📁 程序确定二叉树的特征。如:每个节点的层次
💻 CPP
字号:
#include<iostream.h>
#include"binary.h"


void detail(BST<int> testree)
{
	char ans;
	int number;
	cout<<"Do you want to know the characters of a certain number?('Y' or 'N')\n";
	cin>> ans;
	while ((ans!='N') && (ans!='n'))
	{
		cout<<"Enter the number of which you want to know the characters: \n";
		cin>>number;
		cout<< "Charactors of " << number <<" are as follows: \n";
		cout<< "level:  " << testree.level(number) <<endl;
		cout<< "length of path:  " << testree.level(number)-1 <<endl;
		cout<< "number of descendants: " << testree.size(number)-1 <<endl;
		cout<< "number of ancestors: " << testree.level(number)-1 <<endl;
		cout<<"Do you want to know the characters of a certain number?('Y' or 'N')\n";
		cin>> ans;
	};
	cout<<endl;
}

void main()
{
	BST<int> testree;
	int number;
	char choice;
	cout<<"This program gives some certain chracters of a binary tree!\n";
	cout<<"First construct a binary tree.\n";
	cout<<"Input numbers(nodes) one by one. Take 0 as the end!\n";
	while((cin>> number) && (number!=0))
	{
		testree.insert(number);
	}
	cout<<endl<<"The tree you have entered is as follows: \n";
	testree.print();
	cout<<endl<<endl;
	cout <<"What do you want to know about the tree?\n";
	cout << "D : Show some detail information of each node; " << endl;
	cout << "P : Show the order number of each node in preorder visiting; " << endl;
	cout << "M : Show the order number of each node in inorder visiting; " << endl;
	cout << "Q : Show the order number of each node in postorder visiting; " << endl;
	cout << "S : Help yo get the detail information of a certain node; "<<endl;
	cout << "Please input your choice, or press Ctrl+C to quit: ";

	while (cin >> choice)
	{
		cout << endl;
		if (choice > 90)
			choice = choice - 32;
		switch (choice)
		{
		case 'D':
			testree.biglevel();
			break;
		case 'P':
			testree.preorder();
			break;
		case 'M':
			testree.inorder();
			break;
		case 'Q':
			testree.postorder();
			break;
		case 'S':
			detail(testree);
			break;
		default:
			cout << endl << "You've got a wrong input! Please try again!" << endl;
		}
		cout<<endl<<endl;
		cout <<"What do you want to know about the tree?\n";
		cout << "D : Show the level of each node; " << endl;
		cout << "P : Show numbers in preorder visiting; " << endl;
		cout << "M : Show numbers in inorder visiting; " << endl;
		cout << "Q : Show numbers in postorder visiting; " << endl;
	    cout << "S : Help yo get the detail information of a certain node;" <<endl;
		cout << endl << "Please input your choice, or press Ctrl+C to quit: ";
	}
	cout<<endl;
}

⌨️ 快捷键说明

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