本文整理汇总了C++中BinaryTree::find方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryTree::find方法的具体用法?C++ BinaryTree::find怎么用?C++ BinaryTree::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryTree
的用法示例。
在下文中一共展示了BinaryTree::find方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: find
BinaryTree* find(int val){
if(value == val)
return this;
else{
if(val<value){
if(left != NULL)
return left->find(val);
return NULL;
}else{
if(right != NULL)
return right->find(val);
return NULL;
}
}
}
示例2: run
//generates output and puts it in data vector
void run(){
while( ((structIsaBTree) ? bt.getCurrentTime()<limit : c.getCurrentTime()<limit) && ((structIsaBTree) ? bt.getHead()!=nullptr : c.getGroupSums()>0) ){
entry vecPos = (structIsaBTree) ? bt.find() : c.selectRate();
//std::cout<<vecPos.first<<" "<<vecPos.second.first<<" "<<vecPos.second.second<<"\n";
if (vecPos.second.second>2){
if (vecPos.second.second==3){
addCreature(creatures[vecPos.second.first-1].get("positionX"));
std::vector< entry > nCreature{ {10,{creatures.size(),1}}, {10,{creatures.size(),2}}, {.5,{creatures.size(),3}},{.25,{creatures.size(),4}} };
for (int i = 0; i<nCreature.size();i++){
(structIsaBTree) ? bt.insert(nCreature[i]) : c.addRate(nCreature[i]);
}
}
else{
(structIsaBTree) ? bt.removeAll(vecPos.second,bt.getHead()) : c.deleteC(vecPos.second.first);
}
}
creatures[vecPos.second.first-1].increment(vecPos.second.second);
for (int x = 0; x<creatures.size();x++){
// std::cout<<"creature "<<x+1<<" position "<<creatures[x].get("positionX")<<"\n";
if (creatures[x].get("dead")!=1)
data.push_back({(structIsaBTree) ? bt.getCurrentTime() : c.getCurrentTime() ,creatures[x].get("positionX")});
}
}
std::cout<<"final size: "<<creatures.size()<<"\n";
}
示例3: main
int main()
{
BinaryTree binarytree;
int arr[10] = {8,9,10,3,2,1,6,4,7,5};
for(int i = 0;i < 10; i++)
{
binarytree.insert(arr[i]);
}
int value;
cin >> value;
if(binarytree.find(value))
{
cout << "search success" << endl;
}
else
{
cout << "search failed " << endl;
}
cin >> value;
if(binarytree.remove(value))
{
cout << "delete success" << endl;
}
else
{
cout << "delete failed" << endl;
}
return 0;
}
示例4: main
int main() {
using namespace std;
vector<string> vs;
getDictionary( back_inserter(vs), 5000, SORTED, dpath );
BinaryTree<string> tree;
for( vector<string>::iterator i(vs.begin()); i != vs.end(); ++i )
tree.insert( *i );
{
Timer t;
for( vector<string>::iterator i(vs.begin()); i != vs.end(); ++i )
const string *tmp( tree.find(*i) );
cout << "find (normal return): " << t << endl;
}
{
Timer t;
for( vector<string>::iterator i(vs.begin()); i != vs.end(); ++i )
const string *tmp( tree.efind(*i) );
cout << "efind (exception return): " << t << endl;
}
return 0;
}