testprogbinarysearchtree.cpp

来自「data+structures+using+c的源码」· C++ 代码 · 共 54 行

CPP
54
字号

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

using namespace std;

void print(int& x);									
void update(int& x);								

int main()											
{
	bSearchTreeType<int>  treeRoot;					//Line 1
		
	int num;										//Line 2

	cout<<"Line 3: Enter numbers ending with -999"	
		<<endl;										//Line 3
	cin>>num;										//Line 4

	while(num != -999)								//Line 5
	{
		treeRoot.insert(num);						//Line 6
		cin>>num;									//Line 7
	}

	cout<<endl<<"Line 8: Tree nodes in inorder: ";	//Line 8
	treeRoot.inorderTraversal(print);				//Line 9
	cout<<endl<<"Line 10: Tree Height: "
		<<treeRoot.treeHeight()
		<<endl<<endl;								//Line 10

	cout<<"Line 11: ******* Update Nodes *******"
		<<endl;										//Line 11
	treeRoot.inorderTraversal(update);				//Line 12

	cout<<"Line 13: Tree nodes in inorder after "
		<<"the update: "<<endl<<"         ";		//Line 13
	treeRoot.inorderTraversal(print);				//Line 14
	cout<<endl<<"Line 15: Tree Height: "
		<<treeRoot.treeHeight()
		<<endl;										//Line 15

	return 0;										//Line 16
}

void print(int& x)									//Line 17
{
	cout<<x<<" ";									//Line 18
}	

void update(int& x)									//Line 19
{
	x = 2 * x;										//Line 20
}

⌨️ 快捷键说明

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