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


C++ AVL类代码示例

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


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

示例1: main

//Main function
int main()
{
	AVL *a = new AVL();
	string str;
	int val;
	cin >> str;	
	clock_t start, end;
	start = clock();
	while(!cin.eof())
	{
		if(str.compare("insert") == 0)
		{
			cin >> val;
			if((a->access(val)) == true)
				cout << "Element already inserted" << endl;
			else
			{
				a->insert(val);
				cout << "Element inserted" << endl;
			}
		}
		
		if(str.compare("access") == 0)
		{
			cin >> val;
			if((a->access(val)) == true)
				cout << "Element accessed" << endl;
			else
				cout << "Element not found" << endl;
		}
开发者ID:exyrion,项目名称:bst_avl_splay,代码行数:31,代码来源:avl.cpp

示例2: main

int main() {
    AVL avl;
    avl.insert(5);
    avl.print();
    avl.insert(3);
    avl.print();
}
开发者ID:richard-liang,项目名称:leetcode,代码行数:7,代码来源:avl.cpp

示例3: search

int AVLHash :: search(int k)
{
        int pos = hashCode(k);
        AVL *tree = hash_table[pos];

        return tree->search(k);
}
开发者ID:Mengqi,项目名称:Cpp,代码行数:7,代码来源:avlhash.cpp

示例4: insert

void AVLHash :: insert(int k, int v)
{
        int pos;
        AVL *tree;

        pos = hashCode(k);
        tree = hash_table[pos];
        tree->insert(k, v);
}
开发者ID:Mengqi,项目名称:Cpp,代码行数:9,代码来源:avlhash.cpp

示例5: printTreeStatus

void printTreeStatus(const AVL<T> &t) {
    cout << "----------------------------------------" << endl;
    if (t.isEmpty()) cout << "The tree is empty" << endl;
    else {
        cout << "Tree root is: " << t.root() << endl;
        cout << "Tree height is: " << t.height() << endl;
        cout << "Tree contains " << t.size() << " elements" << endl;
    }
    cout << "----------------------------------------" << endl;
}
开发者ID:0x0all,项目名称:algorithms-1,代码行数:10,代码来源:avl_demo.cpp

示例6: main

int main()
{
    int n,x;
    AVL <int> avl;
    cout<<"input the number of elements:";
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>x,avl.insert(x);
    avl.print();
    return 0;
}
开发者ID:eecrazy,项目名称:acmcode,代码行数:11,代码来源:AVL平衡树.cpp

示例7: main

int main(void){
   AVL tree;
   tree.insert(10);
   tree.insert(30);
   tree.insert(20);
   tree.insert(15);
   tree.insert(18);
   tree.insert(16);
   cout << "*************************" << endl;
   tree.inOrderPrint();
      
}
开发者ID:cathyatseneca,项目名称:dsa555.f12,代码行数:12,代码来源:avl.cpp

示例8: main

int main(void){
	AVL avl;
	avl.insert(10);
	avl.insert(5);
	avl.insert(20);
	avl.insert(3);
	avl.insert(15);
	avl.insert(8);
	avl.insert(25);
	avl.insert(7);
	avl.insert(2);
	avl.insert(9);
	avl.insert(6);
}
开发者ID:vu2srk,项目名称:Problem-solving-and-DS,代码行数:14,代码来源:avl.cpp

示例9: 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

示例10: ARC033_C

signed ARC033_C(){
  int q;
  cin>>q;
  AVL<Int> avl;
  for(int i=0;i<q;i++){
    int t,x;
    cin>>t>>x;
    if(t==1) avl.insert(x);
    else{
      Int key=avl.rank(x-1)->key;
      cout<<key<<endl;
      avl.erase(key);
    }
  }
  return 0;
}
开发者ID:beet-uoa,项目名称:library,代码行数:16,代码来源:avltree.cpp

示例11: ARC028_B

signed ARC028_B(){
  int n,k;
  cin>>n>>k;
  int x[n];
  for(int i=0;i<n;i++) cin>>x[i];
  map<int,int> m;
  for(int i=0;i<n;i++) m[x[i]]=i+1;
  AVL<Int> avl;
  for(int i=0;i<k-1;i++) avl.insert(x[i]);
  for(int i=k-1;i<n;i++){
    avl.insert(x[i]);
    Int key=avl.rank(k-1)->key;
    cout<<m[key]<<endl;
    assert(avl.index(key)==k-1);
  }
  return 0;
}
开发者ID:beet-uoa,项目名称:library,代码行数:17,代码来源:avltree.cpp

示例12: main

/**** Programa Principal ******************************************************/
int main(){
    //Variables locales
    AVL<int> v;
    int e;
    int op=0;
	while (op!=12)
	{
		cout<<"________________________________________________________________________________"<<endl
		<<"                                 ADT Arbol AVL"<<endl
		<<"________________________________________________________________________________"<<endl<<endl
		<<"             ___________________________________________________________"<<endl
		<<"            |      [ 1 ]  Meter elemento                                |"<<endl
		<<"            |      [ 2 ]  Sacar elemento                                |"<<endl
		<<"            |      [ 3 ]  Inorden                                       |"<<endl
		<<"            |      [ 4 ]  Preorden                                      |"<<endl
		<<"            |      [ 5 ]  Postorden                                     |"<<endl
		<<"            |      [ 6 ]  Inorden Inv.                                  |"<<endl
		<<"            |      [ 7 ]  Preorden Inv                                  |"<<endl
		<<"            |      [ 8 ]  Postorden Inv                                 |"<<endl
		<<"            |      [ 9 ]  Hijos                                         |"<<endl
		<<"            |      [ 10 ]  Camino                                       |"<<endl
		<<"            |      [ 11 ]  Altura                                       |"<<endl
		<<"            |___________________________________________________________|"<<endl<<endl
		<<"             Opcion a Elegir: ";
		
		cin>>op;
		system("cls");

		if (op==1)
		{
                  
            cout<<"Dame un numero a insertar ";          
            cin>>e;           
			v.meter(e);
			system("pause");
			system("cls");
		}
		if (op==2)
		{
                  
            cout<<"Dame un numero a sacar ";          
            cin>>e;           
			v.sacar(e);
			system("pause");
			system("cls");
		}
开发者ID:poz2k4444,项目名称:data-structure,代码行数:47,代码来源:pruebaavl.cpp

示例13: isInOrder

bool isInOrder(AVL<T> const &in) {
  vector<T> list = in.inOrder();
  for (auto it = list.begin() + 1; it < list.end(); it++) {
    if (*it < *(it - 1))
      return false;
  }
  return true;
}
开发者ID:anthonyrgreen,项目名称:Interview-Practice,代码行数:8,代码来源:AVL.cpp

示例14: main

int main() {
  AVL<int>* avl = new AVL<int>();
  //AVL<double>* avlD = new AVL<double>();
  //AVL<std::string>* avlS = new AVL<std::string>();
  
  cout << "Pre Order Traversal Print" << endl;
  cout << endl;
  avl->insert(4);
  avl->insert(2);
  avl->insert(3);
  avl->insert(7);
  avl->insert(1);
  avl->insert(17);
  avl->insert(16);
  avl->insert(5);
  avl->print();
  cout << endl;
/*
  cout << "Post Order Traversal" << endl;
  avl->postOrderTraversal();
  cout << endl;
  
  cout << "In Order Traversal" << endl;
  avl->inOrderTraversal();
  cout << endl;
  cout << "End!" << endl;*/
}
开发者ID:GregGay,项目名称:csci333-avl,代码行数:27,代码来源:avl_test.cpp

示例15: 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);
}
开发者ID:tantantzp,项目名称:datastructure,代码行数:36,代码来源:main.cpp


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