当前位置: 首页>>代码示例>>C++>>正文


C++ AVL::is_balanced方法代码示例

本文整理汇总了C++中AVL::is_balanced方法的典型用法代码示例。如果您正苦于以下问题:C++ AVL::is_balanced方法的具体用法?C++ AVL::is_balanced怎么用?C++ AVL::is_balanced使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AVL的用法示例。


在下文中一共展示了AVL::is_balanced方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(){
	FileIO * file = new FileIO("tube.txt");

	vector<Station *> station_list = file->read_file_to_station_list();
	vector<Station *> sorted_list = file->read_file_to_station_list();
	std::sort(sorted_list.begin(), sorted_list.end(), sort_by_name);
//	print_all(sorted_list, station_list);

//	search_by_keyword(sorted_list, station_list);
//	mode_selection(sorted_list, station_list);
	//test section

	node<int> *_node = new node<int>();
//	cout<<sorted_list[0]->get_station_index()<<endl;
	_node->data = sorted_list[0]->get_station_index();
	AVL<int> *tree = new AVL<int>(_node); //new binary_tree<int>(_node);

	for(vector<Station *>::iterator it = sorted_list.begin() + 1;it != sorted_list.end();++it){
		bool b_return = tree->insert((*it)->get_station_index());
//		cout<<(*it)->get_station_index()<<"  "<<b_return<<endl;
	}
	cout<<"done!"<<endl;
//	tree->traverse_inorder(tree->root);
	cout<<"Tree height is "<<tree->tree_height<<endl;
	node<int> *returned_node = tree->search(0);
	cout<<returned_node->data<<" "<<returned_node->height<<endl;
	node<int> *rhs = tree->root;
//	cout<<rhs->data<<" "<<rhs->height<<endl;
	rhs = rhs->rhs;
	node<int> min, max;
//	cout<<"d 1"<<endl;
	tree->find_min_from(rhs, min);
//	cout<<"d 2"<<endl;
	tree->find_max_from((tree->root)->lhs, max);
	cout<<"min in right branch is "<<min.data<<" "<<min.height<<endl;
	cout<<"max in left branch is "<<max.data<<" "<<max.height<<endl;

	cout<<"depth is "<<tree->find_depth(tree->root)<<endl;
	cout<<"left branch depth is "<<tree->find_depth((tree->root)->lhs)<<endl;
	cout<<"right branch depth is "<<tree->find_depth((tree->root)->rhs)<<endl;
	cout<<"balance factor is "<<tree->balance_factor(tree->root)<<endl;
	cout<<"tree is balanced? "<<tree->is_balanced(tree->root)<<endl;

	cout<<"tree root "<<(tree->root)->data<<endl;
//	delete[] tree->root;
	delete tree;
	return 0;
}
开发者ID:TedCAI,项目名称:London-Tube-Path-Search,代码行数:48,代码来源:binary_tree.cpp


注:本文中的AVL::is_balanced方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。