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


C++ AvlTree::remove方法代码示例

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


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

示例1: main

int main()
{

AvlTree<int, int> k;
for(int i=1;i<100;i++)
k.insert(i,i*10);

for(int i=1;i<100;i++) 
cout << k.lookupNode(i) << endl;

for(int i=100;i<200;i++)
k.insert(i,i*10);


for(int i=1;i<200;i++) 
cout << k.lookupNode(i) << endl;

for(int i=1;i<100;i++)  
k.remove(i);

for(int i=1;i<200;i++)
cout << k.lookupNode(i) << endl;


return 0;
}
开发者ID:Amortized,项目名称:Algorithms-and-Data-Structures,代码行数:26,代码来源:avltree.cpp

示例2: main

// Test program
int main( )
{
    AvlTree<int> t;
    int NUMS = 2000000;
    const int GAP  =   37;
    int i;
    
    cout << "Checking... (no more output means success)" << endl;
    
    for( i = GAP; i != 0; i = ( i + GAP ) % NUMS )
        t.insert( i );
    t.remove( 0 );
    for( i = 1; i < NUMS; i += 2 )
        t.remove( i );
    
    if( NUMS < 40 )
        t.printTree( );
    if( t.findMin( ) != 2 || t.findMax( ) != NUMS - 2 )
        cout << "FindMin or FindMax error!" << endl;
    
    for( i = 2; i < NUMS; i += 2 )
        if( !t.contains( i ) )
            cout << "Find error1!" << endl;
    
    for( i = 1; i < NUMS; i += 2 )
    {
        if( t.contains( i )  )
            cout << "Find error2!" << endl;
    }
    
    AvlTree<int> t2;
    t2 = t;
    
    for( i = 2; i < NUMS; i += 2 )
        if( !t2.contains( i ) )
            cout << "Find error1!" << endl;
    
    for( i = 1; i < NUMS; i += 2 )
    {
        if( t2.contains( i ) )
            cout << "Find error2!" << endl;
    }
    
    cout << "End of test..." << endl;
    return 0;
}
开发者ID:nickruta,项目名称:DataStructuresAlgorithmsCpp,代码行数:47,代码来源:TestAvlTree.cpp

示例3: main

int main() {
    AvlTree t;
    t.insert(2);
    t.insert(1);
    t.insert(3);
    t.insert(5);
    t.insert(0);
    t.insert(3);
    printf("min %d max %d\n", t.min_key(), t.max_key());
    assert(5 == t.max_key());
    assert(0 == t.min_key());
    assert(t.contains(0));
    t.remove(0);
    assert(!t.contains(0));
    assert(1 == t.min_key());
    assert(t.contains(1));
    t.remove(1);
    assert(!t.contains(1));
    assert(2 == t.min_key());
    return 0;
}
开发者ID:dr-dos-ok,项目名称:uva-solutions,代码行数:21,代码来源:avl_tree.cpp

示例4: main

int main(){
    AvlTree<char> avl;
    avl.insert('a');
    avl.insert('b');
    avl.insert('c');
    avl.remove('b');
    //cout << avl.toString();
    RBTree<char> rb;
    rb.insert('a');
    rb.insert('b');
    rb.insert('c');
    cout << rb.toString();
    //AvlTree<char>::Node* a = new AvlTree<char>::Node('a');
    //AvlTree<char>::Node* b = new AvlTree<char>::Node('b');
    //AvlTree<char>::Node* c = new AvlTree<char>::Node('c');
    //c->left = a;
    //a->right = b;
    //cout << c->toString() << endl;
    //c->left = a->rotateLeft();
    //cout << c->toString() << endl;
}
开发者ID:evsasse,项目名称:avl-rb-trees,代码行数:21,代码来源:main.cpp

示例5: main

int main(){
  //Define some data
  int data[]={21,13,29,8,18,26,32,5,11,16};
  int data2[]={55,56,57};

  //Define a new AVL tree
  AvlTree<int> tree;

  //Insert data with loop
  for(int i=0;i<10;i++)
    tree.insert(data[i]);

  //Insert data with built-in loop
  tree.insert(data2,3);

  //Print a representation of the tree
  tree.qtreePrint(cout);

  cout<<endl<<endl;

  //Remove some nodes
  tree.remove(13);
  tree.remove(26);

  //Print another representation of the tree
  tree.qtreePrint(cout);

  //Print the number of nodes in the tree
  cout<<endl<<endl<<"Size: "<<tree.size()<<endl;

  cout<<"Value of top node: "<<tree.top()<<endl;
  tree.pop();
  cout<<"Value of top node: "<<tree.top()<<endl;

  return 0;
}
开发者ID:r-barnes,项目名称:RAVL,代码行数:36,代码来源:example.cpp

示例6: main

int main()
{
	AvlTree<Soundtrack> avlTree;
	vector<Soundtrack> cdVector;  // Holds soundtrack objects created from file input
	string fileName = "Topic F Soundtrack.txt";  // File to open
	bool ableToOpen;  // Test success of opening file

	cout << "Create and populate AVL tree\n\n";
	
	do {
		ableToOpen = openFile(fileName, cdVector, avlTree);
		if (!ableToOpen)
		{
			cout << fileName << " cannot be opened.  Enter another file name -->  ";
			getline(cin, fileName);
		}
	} while (!ableToOpen);

	continueProgram();

	cout << "Get item with key \"FSMBox 03 Disc 8\":\n\n";
	Soundtrack FSM;
	FSM.setLabel("FSM");
	FSM.setCatalogNumber("Box 03 Disc 8");
	if ( !avlTree.get(FSM) )
		cout << "No items found with key \"FSMBox 03 Disc 8\"\n\n";
	cout << "\n\nGet item with key \"FSMBox 07 Disc 8\":\n\n";
	Soundtrack FSM2;
	FSM2.setLabel("FSM");
	FSM2.setCatalogNumber("Box 07 Disc 8");
	if (!avlTree.get(FSM2))
		cout << "No items found with key \"FSMBox 07 Disc 8\"\n";

	continueProgram();

	cout << "Listing of all items in the tree: (There are " << avlTree.getNumberOfNodes() << " items in the tree)\n\n";
	avlTree.inorderTraverse(display);

	continueProgram();

	cout << "\n\nList all soundtracks recorded in the 1950s:\n\n";
	vector<Soundtrack> matchedYear;
	getYear(cdVector, matchedYear);
	for (unsigned int i = 0; i < matchedYear.size(); i++)
	{
		if (avlTree.get(matchedYear[i]))
			cout << matchedYear[i];
	}

	continueProgram();

	cout << "\n\nDelete all items with key \"FSM V8N11\":";
	Soundtrack dltFSM;
	dltFSM.setLabel("FSM");
	dltFSM.setCatalogNumber("V8N11");
	if (avlTree.get(dltFSM))
	{
		avlTree.remove(dltFSM);
		cout << dltFSM << "\nhas been deleted\n\n";
	}
	cout << "Again delete all items with key \"FSM V8N11\":\n";
	if (avlTree.get(dltFSM))
	{
		avlTree.remove(dltFSM);
		cout << dltFSM << "\nhas been deleted\n\n";
	}
	else
		cout << "NO items for \"FSM V8N11\"";

	continueProgram();

	cout << "\nListing of all items in the tree: (There are " << avlTree.getNumberOfNodes() << " items in the tree)\n";
	avlTree.inorderTraverse(display);

	cin.ignore( cin.rdbuf()->in_avail() );
	cout << "\n\nProgram Ending\n\n";
	cout << "Press Enter to end -->  ";
	cin.ignore();
}  // end main
开发者ID:Jeff457,项目名称:M20-Topic-F,代码行数:79,代码来源:TopicF.cpp

示例7: gerarArquivosDat


//.........这里部分代码省略.........
    //Ela é retornada em ordem de nível para ser escrita nessa ordem
    int maxSize = indices.getMaxSizeByHeight();
    Indice* indicesOrdenados;
    indicesOrdenados = indices.getByLevel();
    printf("Organizou por nivel");
    
    //Abre ou cria o arquivo indices.dat para escrita
    FILE* indicesDat;
    indicesDat = fopen("..\\indices.dat","wb");
    
    printf("Abriu e comecou a gerar indices.dat\n");
    
    //percorre cada indice da lista
    for(int i=0;i<maxSize;++i){
        //coloca os valores que serão passado para o arquivo em "comando"
        char comando[100];
        for(int c=0;c<comandoTamMax;++c){
            comando[c] = indicesOrdenados[i].comando[c];
        }
        printf("%d - %s\n",(i+1),comando);
        //e em "posicao"
        int posicao = indicesOrdenados[i].posicao;
        //troca os 4 ultimos bytes de comando, guardando a posição.
        //*((int*)&a[96]) = 123;
        *((int*)&comando[96]) = posicao;
        
        for(int i=0;i<comandoTamMax;++i){
            fputc(comando[i],indicesDat);
        }
    }
    delete indicesOrdenados;
    
    //fecha o arquivo indices.dat
    fclose(indicesDat);
    printf("Terminou de gerar indices.dat\n");
    
    ///////////////////////////////////
    ///// TERMINOU A INDICES.DAT
    ///////////////////////////////////
    ///// COMEÇOU O PALAVRAS.DAT
    ///////////////////////////////////
    
    FILE* palavrasDat;
    palavrasDat = fopen("..\\palavras.dat","wb");
    printf("Abriu e comecou a gerar palavras.dat\n");
    printf("%d|%d\n",palavras.getSize(),palavras.getMaxSizeByHeight());
    
    //Exclui conectivos da árvore
    for(int i=0;i<qtdConectivos;i++){
        char conectivo[100];
        strcpy(conectivo,conectivos[i]);
        palavras.remove(Palavra(conectivo,0));
    }
    
    //Gera palavras ordenadas para inserção
    Palavra* palavrasOrdenadas = palavras.getByLevel();
    printf("Gerou palavras ordenadas");
    
    //Escreve qtd de palavras
    maxSize = palavras.getMaxSizeByHeight();
    char maxSizeW[4];
    *((int*)&maxSizeW[0]) = maxSize;
    for(int i=0;i<4;++i){
        fputc(maxSizeW[i],palavrasDat);
    }
    //Escreve palavras seguidas do inicio de local das posicoes,e a qtd de posicoes
    //"wait                         0 4"
    int posicao = 0;
    for(int i=0;i<maxSize;++i){
        Palavra atual = palavrasOrdenadas[i];
        printf("%d - %s\n",i,atual.palavra);
        *((int*)&atual.palavra[92]) = posicao;
        int qtd = atual.posicoes.size();
        *((int*)&atual.palavra[96]) = qtd;
        posicao += qtd;
        for(int i=0;i<100;++i){
            fputc(atual.palavra[i],palavrasDat);
        }
    }
    //Escreve as posicoes das manpages que contem as palavras
    char pos[4]; //converter o int para binário
    for(int i=0;i<maxSize;++i){
        Palavra atual = palavrasOrdenadas[i];
        while(!atual.posicoes.empty()){
            *((int*)&pos[0]) = atual.posicoes.front();
            atual.posicoes.pop_front();
            for(int i=0;i<4;++i){
                fputc(pos[i],palavrasDat);
            }
        }
    }
    
    fclose(palavrasDat);
    
    printf("Terminou de gerar palavras.dat\n");
    
    ///////////////////////////////////
    ///// TERMINOU A PALAVRAS.DAT
    ///////////////////////////////////
}
开发者ID:evsasse,项目名称:manpage-search,代码行数:101,代码来源:main.cpp


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