本文整理汇总了C++中AVL::search方法的典型用法代码示例。如果您正苦于以下问题:C++ AVL::search方法的具体用法?C++ AVL::search怎么用?C++ AVL::search使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AVL
的用法示例。
在下文中一共展示了AVL::search方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: search
int AVLHash :: search(int k)
{
int pos = hashCode(k);
AVL *tree = hash_table[pos];
return tree->search(k);
}
示例2: testAVL
/******************************************************************************************
* Test an AVL
******************************************************************************************/
template <typename T> void testAVL(int n) {
AVL<T>* avl = new AVL<T>;
while (avl->size() < n) {
T e = dice((T)n*3); //[0, 3n)范围内的e
switch (dice(3)) {
case 0: { //查找,成功率 <= 33.3%
printf("Searching for "); print(e); printf(" ...\n");
BinNodePosi(T) & p = avl->search(e);
p ?
printf("Found with"), print(p), printf("\n") :
printf("Not found\n");
break;
}
case 1: { //删除,成功率 <= 33.3%
printf("Removing "); print(e); printf(" ...\n");
avl->remove(e) ? printf("Done\n"), print(avl) : printf("Not exists\n");
break;
}
default: {//插入,成功率 == 100%
printf("Inserting "); print(e); printf(" ...\n");
BinNodePosi(T) p = avl->insert(e);
printf("Done with"), print(p), printf("\n"), print(avl);
break;
}
}
}
while (avl->size() > 0) {
T e = dice((T)n*3); //[0, 3n)范围内的e
printf("Removing "); print(e); printf(" ...\n");
avl->remove(e) ? printf("Done\n"), print(avl) : printf("Not exists\n");
}
release(avl);
}
示例3: 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;
}