예제 #1
0
int main (int argc, char *argv[]){
    std::ifstream inputFileA;
    std::ifstream inputFileC;
    std::string b;
	std::cout<<argv[1];
    
    if(argc<2){
        std::cout<<"Argumentos insuficientes!"<<std::endl;
        std::cout<<"É preciso a inserção de mais argumentos!"<<std::endl;
        std::cout<<"A forma geral de chamada do programa é:"<<std::endl;
        std::cout<<"./bin/main arquivo_entrada arquivo_de_comandos"<<std::endl;
        return 1;
    }

	inputFileA.open(argv[1],std::ifstream::in);
	inputFileC.open(argv[2],std::ifstream::in);
	
	if(!inputFileA.is_open()||!inputFileC.is_open()) {
		if(!inputFileA.is_open())
			std::cout<<"Erro ao abrir o arquivo "<<argv[1]<<std::endl;
		if(!inputFileC.is_open())
			std::cout<<"Erro ao abrir o arquivo "<<argv[2]<<std::endl;
		return 1;
	}
	
	ABB abb;
	
	std::string input;

	std::getline(inputFileA,input);
	std::stringstream stream(input);
	int a;
	while(1){
		stream>>a;
		abb.insert(a);
		if(!stream)
			break;
	}

    
    while(!inputFileC.fail()){
		std::getline(inputFileC,input);
		
		std::stringstream ss;
		if(input.find("ENESIMO")!=std::string::npos){
			int a;
			ss<<input;
			ss>>a;
			std::cout<<abb.nElement(a);
		}
		else if(input.find("POSICAO")!=std::string::npos){
예제 #2
0
void ler_comando(std::string c, ABB &arv) {
	std::string aux;
	int x;
	while (!c.empty()){
		if(c.front() == ' ') {
        	c.erase(0,1);
        	break;
        }
        else{
            aux = aux + c.front();
            c.erase(0,1);
        }
    }

    if (!c.empty()) {
    	x = std::stoi (c, nullptr, 10);
    }

    if (aux == "ENESIMO") {
    	std::cout << "O elemento na " << x << "ª posicao eh o: " << arv.enesimoElemento(x) << std::endl;
    }

    else if (aux == "POSICAO") {
    	std::cout << "O elemento " << x << " esta na " << arv.posicao(x) << "ª posicao" << std::endl;
    }


    else if (aux == "MEDIANA") {
    	std::cout << "A mediana da ABB eh o elemento: " << arv.mediana() << std::endl;
    }

    else if (aux == "CHEIA") {
    	if (arv.ehCheia()) {
    		std::cout << "A ABB eh cheia!" << std::endl;
    	}
    	
    	else
    		std::cout << "A ABB Nao eh cheia! " << std::endl;
    }

    else if (aux == "COMPLETA") {
    	if (arv.ehCompleta()) {
			std::cout << "A ABB eh completa!" << std::endl;
    	}

    	else 
    		std::cout << "A ABB nao eh completa!" << std::endl;
    }

    else if (aux == "IMPRIMA") {
    	std::cout << "Imprimindo ABB por nivel: " << arv.toString() << std::endl;
    }

    else if (aux == "REMOVA") {
    	std::cout << "Removendo o elemento: " << x << " ..." << std::endl;
    	arv.remocao(x);
    }

}
예제 #3
0
void iniciarABB(std::string c, ABB &arv){
    int x;

    std::string aux;
    while (!c.empty()){
        if(c.front() == ' ') {
        	x = std::stoi (aux, nullptr, 10);
        	aux.clear();
        	arv.inserir(x);
        	c.erase(0,1);
        }
        else{
            aux = aux + c.front();
            c.erase(0,1);
        }
    }

    if (!aux.empty()) {
    	x = std::stoi (aux, nullptr, 10);
        aux.clear();
        arv.inserir(x);
    }
}
예제 #4
0
int main()
{
    
    ABB<int> arbol;
    int numcase=1;
    cin>>dimensions;
    rows= columns = dimensions-1;
	while(dimensions != -1){
        
		for(int r=0; r < dimensions; r++){
			for (int c = 0; c < dimensions; c++)
			{
				cin>>matrix[r][c];
			}
            
		}
        
        for (int i=dimensions-1; 0<=i; i--) {
            for (int j=0; j<dimensions; j++) {
                if (!(arbol.existe(matrix[j][i])) && (matrix[j][i]!= 0)) {
                     arbol.inserta(matrix[j][i]);
                }
               
              
            }
        }
        //arbol.despliega();
        cout<<"Case "<<numcase<<":"<<endl;
        cout<<"The height of the BST is: "<<arbol.altura()<<endl;
        int numNodos = arbol.cuenta();
        double numComp = arbol.comparar(1);
        double ans= numComp/numNodos;
       
        cout<<"The average of the search in the BST is: "<<setprecision(3)<<ans <<endl;
        
        arbol.vaciar();
        
		cin>>dimensions;
		numcase++;
	}
    
}
예제 #5
0
int main() {
    /*
    	ABB<char> arbol;
    int opcion, frecuencia, res, el, nivel, existe=1;
    char elem;
    	do
    	{
    	system("cls");
    	cout << "###############################################################################" << endl;
    	cout << "#                                                                             #" << endl;
    	cout << "#                                 ARBOL BINARIO                               #" << endl;
    	cout << "#                                                                             #" << endl;
    	cout << "###############################################################################" << endl;
    	cout << "[1]  InsertarABB" << endl;
    	cout << "[2]  RecorrerINORDER" << endl;
    	cout << "[3]  RecorrerPREORDER" << endl;
    	cout << "[4]  RecorrerPOSTORDER" << endl;
    	cout << "[5]  MostrarNivelABB" << endl;
    	cout << "[6]  ContarNodosABB" << endl;
    	cout << "[7]  CalcularAlturaABB" << endl;
    	cout << "[8]  MenorABB" << endl;
    	cout << "[9]  MayorABB" << endl;
    	cout << "[10]  EliminarDadoABB" << endl;
    	cout << "[11] BuscarABB" << endl;
    	cout << "[12] SALIR" << endl;
    	cout << "Ingresar opcion: " ;
    	cin >> opcion;
    	switch (opcion)
    	{
    		   case 1:
    				 cout<<"elemento:";
    				 cin>>elem;cout<<endl;
    				 cout<<"frecuencia: ";
    				 cin>>frecuencia;

    				 arbol.insertarABB(arbol.RAIZ,elem,frecuencia);


    				 system("pause");
    				 system("cls");
    				 break;

    			case 2:
    				 arbol.recorrerIN(arbol.RAIZ);
    				 cout<<endl;
    				 system("pause");
    				 system("cls");
    				 break;

    			case 3:
    				 arbol.recorrerPRE(arbol.RAIZ);
    				 cout<<endl;
    				 system("pause");
    				 system("cls");
    				 break;

    			case 4:
    				 arbol.recorrerPOST(arbol.RAIZ);
    				 cout<<endl;
    				 system("pause");
    				 system("cls");
    				 break;

    			case 5:
    				 cout<<"Nivel:";
    				 cin>>nivel;
    				 arbol.mostrarNivel(arbol.RAIZ,nivel,1);
    				 system("pause");
    				 system("cls");
    				 break;

    			case 6:
    				 res=arbol.contarNodosABB(arbol.RAIZ);
    				 cout<<res<<endl;
    				 system("pause");
    				 system("cls");
    				 break;

    			case 7:
    				 res=arbol.calcularAlturaABB(arbol.RAIZ);
    				 cout<<res<<endl;
    				 system("pause");
    				 system("cls");
    				 break;

    			case 8:
    				 res=arbol.menorABB(arbol.RAIZ,&existe);
    				 if(existe==0){
    				 cout<<"NO"<<endl;
    				 }else{
    				 cout<<res<<endl;}
    				 system("pause");
    				 system("cls");
    				 break;

    			case 9:
    				 res=arbol.mayorABB(arbol.RAIZ,&existe);
    				 if(existe==0){
    				 cout<<"NO"<<endl;
    				 }else{
    				 cout<<res<<endl;}
    				 system("pause");
    				 system("cls");
    				 break;

    			case 10:

    				 system("pause");
    				 system("cls");
    				 break;

    			case 11:
    				 cout<<"elemento:";
    				 cin>>el;
    				 res=arbol.buscarABB(arbol.RAIZ,el);
    				 cout<<res<<endl;
    				 system("pause");
    				 system("cls");
    				 break;

    			case 12:cout<<"Saliendo..."<<endl;
    	}

    }while(opcion <=12 && opcion!=12);
    */
    ListaForma8<char> lf8;
    ABB<char> arbol;
    string binarios[32];
    char el;
    string cod1,cod2,cod3,cod4,cod5,cod6,cod7;
    int opcion, res, existe = 0, frecuencia=0;

    do
    {
        system("cls");
        cout << "###############################################################################" << endl;
        cout << "#                                                                             #" << endl;
        cout << "#                                  LISTA FORMA8                               #" << endl;
        cout << "#                                                                             #" << endl;
        cout << "###############################################################################" << endl;
        //cout << "[1]   InsertarPRIN" << endl;
        //cout << "[2]   InsertarFIN" << endl;
        //cout << "[3]   EliminarPRIN" << endl;
        //cout << "[4]   EliminarFIN" << endl;
        cout << "[5]   MOSTRARLISTA" << endl;
        cout << "[6]   INSERTARENSULUGAR" << endl;
        //cout << "[7]   ELIMINARELEMENTODADO" << endl;
        cout << "[8]   cargar_de_TUAD_a_Lista8" << endl;
        cout << "[9]   crearABB" << endl;
        cout << "[10]  SALIR" << endl;
        cout << "[11]  LLENAR TABLA" << endl;
        cout << "[12]  COMPRIMIR ARCHIVO" << endl;
        cout << "Ingresar opcion: " ;
        cin >> opcion;
        switch (opcion)
        {
        case 1:
            cout<<"elemento:";
            cin >> el;
            cout << endl;
            cout << "frecuencia:";
            cin >> frecuencia;
            res=lf8.insertarPRIN(el,frecuencia);
            cout<<res<<endl;
            system("pause");
            system("cls");
            break;

        case 2:
            cout<<"elemento:";
            cin >> el;
            cout << endl;
            cout << "frecuencia:";
            cin >> frecuencia;
            res = lf8.insertarFIN(el, frecuencia);
            cout<<res<<endl;
            system("pause");
            system("cls");
            break;

        case 3:
            res=lf8.eliminarPRIN();
            cout<<res<<endl;
            system("pause");
            system("cls");
            break;

        case 4:
            res=lf8.eliminarFIN();
            cout<<res<<endl;
            system("pause");
            system("cls");
            break;


        case 5:
            lf8.mostrar();
            system("pause");
            system("cls");
            break;

        case 6:
            /* cout<<"elemento:";
             cin >> el; cout << endl;
             cout << "frecuencia:";
             cin >> frecuencia;*/

            res=lf8.insertarEnSuLUGAR('A',10);
            cout<<res<<endl;
            res=lf8.insertarEnSuLUGAR('B',8);
            cout<<res<<endl;
            res=lf8.insertarEnSuLUGAR('C',6);
            cout<<res<<endl;
            res=lf8.insertarEnSuLUGAR('D',5);
            cout<<res<<endl;
            res=lf8.insertarEnSuLUGAR('E',2);
            cout<<res<<endl;
            //res=lf8.insertarEnSuLUGAR('J',1);
            //cout<<res<<endl;
            system("pause");
            system("cls");
            break;

        case 7:
            cout<<"elemento:";
            cin>>el;
            res=lf8.eliminarDADO(el);
            cout<<res<<endl;
            system("pause");
            system("cls");
            break;

        case 8:
            lf8.extraerCarsTUAD();
            system("pause");
            system("cls");
            break;

        case 9:
            cout<<lf8.crear_arbol();
            cout<<endl;
            //cod = arbol.crearCodigo(lf8.primer->arbol.RAIZ, 'C', "");
            cout<<arbol.calcularAlturaABB(lf8.primer->arbol.RAIZ);
            system("pause");
            system("cls");
            break;
        case 10:
            cout<<"Saliendo..."<<endl;
            break;
        case 11:
            //lf8.llenarTabla();
            cod1 = lf8.primer->arbol.crearCodigo(lf8.primer->arbol.RAIZ, 'A', "");
            cod2 = lf8.primer->arbol.crearCodigo(lf8.primer->arbol.RAIZ, 'B', "");
            cod3 = lf8.primer->arbol.crearCodigo(lf8.primer->arbol.RAIZ, 'C', "");
            cod4 = lf8.primer->arbol.crearCodigo(lf8.primer->arbol.RAIZ, 'D', "");
            cod5 = lf8.primer->arbol.crearCodigo(lf8.primer->arbol.RAIZ, 'E', "");
            cout<<"A => "<<cod1<<endl;
            cout<<"B => "<<cod2<<endl;
            cout<<"C => "<<cod3<<endl;
            cout<<"D => "<<cod4<<endl;
            cout<<"E => "<<cod5<<endl;
            system("pause");
            system("cls");
            break;
        case 12:
            FILE *input, *output;
            input=fopen("texto.txt", "r");
            output=fopen("output.txt","w");
            lf8.comprimirArchivo(input, output, binarios);
            fclose(input);
            fclose(output);
            system("pause");
            system("cls");
            break;


        default:
            opcion=10;
        }

    } while(opcion!=10);
    /*TUAD tuad;
    int opcion = 0;

    do{
    	system("cls");
    	cout << "###############################################################################" << endl;
    	cout << "#                                                                             #" << endl;
    	cout << "#                                 TUAD                                        #" << endl;
    	cout << "#                                                                             #" << endl;
    	cout << "###############################################################################" << endl;
    	cout << "[1]  CargarTxtTUAD" << endl;
    	cout << "[2]  MostrarTUAD" << endl;
    	cout << "[3]  SALIR" << endl;
    	cout << "Ingresar opcion: " ;
    	cin >> opcion;

    	switch (opcion){
    			case 1:
    				 tuad.cargarTxtTUAD();
    				 system("pause");
    				 system("cls");
    				 break;
    			case 2:
    				 tuad.mostrarTUAD();
    				 system("pause");
    				 system("cls");
    				 break;

    			case 3:
    				cout<<"Saliendo..."<<endl;
    				break;
    			default:
    				opcion = 3;
    	}

    }while(opcion!=3);*/



    system("pause");
    system("cls");

    return 0;
}
예제 #6
0
파일: main.cpp 프로젝트: HenrYxZ/tarea2ds
int main(int argc, char *argv[])
{
    srand ( time(NULL) );//se inicializa la semilla de funcion rand()
    
    /*
   ABB* t = new AVLABB();
=======


    Treap t= Treap();
    
    //cout<<"a insertado"<<endl;
    
    //t.insert("b",2);
    
    //t.insert("d",4);
    //t.insert("c",3);
    //t.insert("a",5);
    t.insert("d",4);
    t.insert("a",1);
    t.insert("c",3);
    t.insert("b",2);
    
    
    cout<<t.find("a")<<endl;
    cout<<t.find("b")<<endl;
    cout<<t.find("c")<<endl;
    cout<<t.find("d")<<endl;/*
    t.remove("b");
    t.remove("d");
    cout<<" remove b,d"<<endl;
    cout<<t.find("a")<<endl;
    //cout<<t.find("b")<<endl;
    cout<<t.find("c")<<endl;
    //cout<<t.find("d")<<endl;
    */
    
    
    
    int op;
    cout << "(1) Parte A" << endl;
    cout << "(2) Parte B" << endl;
    cout << "(0) Salir" << endl;
    cin >> op;
    
    if(op == 1)
     {
            system("cls");
           //programa A
           cout << "Ingrese archivo de entrada" << endl;
           string dir;  
           cin >>  dir;
           
           cout << "Ingrese ruta del archivo: " << endl;
           string salida;
           cin >> salida;
        
           // Datos necesarios
           const char* c = dir.c_str();
        
           ifstream file( c );
           
           const char* d = salida.c_str();
           
           ofstream fileout( d );
           string str;
           
           ABB* rb = new RedBlackTree();
           ABB* avl = new AVLABB();
          
           
           //Empieza a leer
        while( getline( file, str ) )
        {
            
            string s;
            istringstream iss(str,istringstream::in);
            getline( iss, s, ' ' );
            string accion = s;    
            getline( iss, s, ' ' );
            string clave = s;
            getline( iss, s, ' ' );
            int prior = str2int(s);
            
            if(accion == "insert")
            {
                      rb->insert(clave,0);
                      avl->insert(clave,0);
                      //aqui cambialo seba, le pones la prioridad
                      
            }
            
            if(accion == "delete")
            {
                      rb->remove(clave);
                      avl->remove(clave);
                      
            }
        
        } //fin de while        
        
        //imprimir los arboles
        
        delete rb;
        delete avl;
        
      system("PAUSE");
      }//fin de opcion 1