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


C++ BinaryTree::get_root方法代码示例

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


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

示例1: main

int main()
{
    BinaryTree<int> *root = new BinaryTree<int>();
    //const unique_ptr<BinaryTreeNode<int>>& node = unique_ptr<BinaryTreeNode<int> root>->get_root();
    BinaryTreeNode<int> *node = new BinaryTreeNode<int>(); //& root;
    root->insert(3);
    root->insert(5);
    root->insert(7);
    root->insert(11);
    node = root->search(3); if (node) std::cout << "found " << node->key_value << std::endl;
    node = root->search(5); if (node) std::cout << "found " << node->key_value << std::endl;
    node = root->search(7); if (node) std::cout << "found " << node->key_value << std::endl;
    node = root->search(11); if (node) std::cout << "found " << node->key_value << std::endl;
    node = root->search(13); if (node) std::cout << "found " << node->key_value << std::endl;
    root->show();
    node = root->get_root();
    bool isbst = IsBST(node);
    std::cout << "isbst? " << (isbst ? "yes" : "no") << std::endl;
    return 0;
}
开发者ID:walrus7521,项目名称:code,代码行数:20,代码来源:15.01.cpp

示例2: main

/* usage:  ./proj5 organisms.txt
 * *******************************************
 * Given a correct file the program takes a list of organisms and
 * constructs its ancestral tree based on the scores in the file.
 * The only output is the string parenthetical expression which
 * represents the closest organisms joined in a tuple of the form
 * ((dog,wolf),mountianGoat)
 *
 */
int main(int argc, char* argv[]){
	std::string addressFile="";
	/*
	 * If the program is ran without sufficient arguments it Will exit gracefully
	 * with suggestions for the usage of the program.
	 */
	if (argc < 2) {
		std::cerr << "Address File not Found\n";
		std::cerr << "Usage:  " << argv[0] << " adresses.txt" << std::endl;
		return -1;
	}

	addressFile=argv[1];
	std::ifstream inFile;
	inFile.open(addressFile.c_str()); // need to open the fileargv[1].c_str()

	if(!inFile){
		write_Log( "Valid File not found:  ** Exiting ** ");
		exit(1);
	}


	std::list< BinaryTree<Organism*> *> treeList;
	/****************************************
	 * Build a vector of Organisms from the file
	 ***********************************************/
	try {
		std::string str;
		std::vector<std::string> data;
		while(std::getline(inFile, str, '\n'))	{

			try{
				 data = split(str);
			}catch(...){
			    	write_Log("**********Exception Throw splitting string:  Line Skipped********");
			    	write_Log("Error Occured IN: "+str);
			    	continue;
			}
			//double score = std::stod (data[1]);
			Organism * toAdd = new Organism(data[0], atoi(data[1].c_str()));
			//Organism * toAdd = new Organism(data[0], score);
			BinaryTree<Organism*> * tree = new BinaryTree<Organism*> (toAdd);
			treeList.push_front(tree);
		}
	} catch(...){
		write_Log( "*********Exception thrown building Binary Trees: *********");
		write_Log("*********Please correct Invalid Input: ********************");
	}
	/********************************************
	 *Initial List of Binary Trees Built
	 *******************************************/
	//write_Log("Length of list of trees =  "+convertDigit(treeList.size()));

	/*******************************************************************
	 * Build LifeTree:
	 * *****************************************************************
	 */
	BinaryTree<Organism*> orgTree;
	buildOrgTree(treeList,orgTree);

	/*
	 *DISPLAY THE FINAL TREES ROOT NODE
	 */
	orgTree.in_order(display);
	write_Log("orgTree has heigh = " + convertDigit(orgTree.height()));
	write_Log(orgTree.get_root()->toString());
	return 0;
}
开发者ID:n-critser,项目名称:cuny-cpp,代码行数:77,代码来源:main.cpp

示例3: print_tree

void print_tree(const BinaryTree& tree) {
    if (tree.get_root() == 0)
        return;
    print_tree(tree.get_root());
}
开发者ID:s-mx,项目名称:Archivator.-smx,代码行数:5,代码来源:compression.cpp


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