示例#1
0
void testgammasparse()
{
	std::ostringstream o0;
	libmaus::gamma::SparseGammaGapEncoder SE0(o0);
	std::ostringstream o1;
	libmaus::gamma::SparseGammaGapEncoder SE1(o1);
	
	SE0.encode(4, 7);
	SE0.encode(6, 3);
	SE0.term();
	
	SE1.encode(0, 1);
	SE1.encode(2, 5);
	SE1.encode(6, 2);
	SE1.encode(8, 7);
	SE1.term();
	
	std::cerr << "o0.size()=" << o0.str().size() << std::endl;
	std::cerr << "o1.size()=" << o1.str().size() << std::endl;
	
	std::istringstream i0(o0.str());
	libmaus::gamma::SparseGammaGapDecoder SD0(i0);
	std::istringstream i1(o1.str());
	libmaus::gamma::SparseGammaGapDecoder SD1(i1);
	
	for ( uint64_t i = 0; i < 10; ++i )
		std::cerr << SD0.decode() << ";";
	std::cerr << std::endl;
	for ( uint64_t i = 0; i < 10; ++i )
		std::cerr << SD1.decode() << ";";
	std::cerr << std::endl;

	std::istringstream mi0(o0.str());
	std::istringstream mi1(o1.str());
	std::ostringstream mo;
	
	libmaus::gamma::SparseGammaGapMerge::merge(mi0,mi1,mo);
	
	std::istringstream mi(mo.str());
	libmaus::gamma::SparseGammaGapDecoder SDM(mi);

	for ( uint64_t i = 0; i < 10; ++i )
		std::cerr << SDM.decode() << ";";
	std::cerr << std::endl;
}
int main(){
    NOH *pilha_t1;
    FRONT_REAR term2, saida;
    // inicialização
    pilha_t1 = NULL; term2.front = NULL; term2.rear = NULL; saida.front = NULL; saida.rear = NULL;
    int i = 1;
    char op[4], f[4] = "FIM", e1[3] = "E1", s1[3] ="S1", e2e[4]="E2E",e2d[4]="E2D", s2e[4]="S2E", s2d[4]="S2D";
            
    do{
        scanf("%s", op); 
        if(strcmp(e1,op)==0) pilha_t1 = E1(pilha_t1, i); //inserir no terminal 1
        else if(strcmp(e2e,op)==0) term2 = E2E(term2, i); //inserir no terminal 2 pela esquerda
        else if(strcmp(e2d,op)==0) term2 = E2D(term2, i);//inserir no terminal 2 pela direita
        //saida terminal 1
        else if(strcmp(s1,op)==0){
            saida = S1(pilha_t1, saida);
            pilha_t1 = SE1(pilha_t1);
        	i--;
        }
        //saida terminal 2 pela esquerda
        else if(strcmp(s2e,op)==0){
            saida = S1(term2.front, saida);
            term2 = liberar_E(term2);
        	i--;
        }
        else if(strcmp(s2d,op)==0){
            saida = S2D(term2, saida);
            term2 = liberar_D(term2);
        	i--;
        }

        i++;
    }while(strcmp(f,op) != 0);
    

    while(pilha_t1 != NULL){
    	saida = S1(pilha_t1, saida);
    	pilha_t1 = SE1(pilha_t1);
    }

    while(term2.front != NULL){
    	saida = S2D(term2, saida);
    	term2 = liberar_D(term2);
    }
    
    int check = 0;
    //mostrar resultado
    while((saida.front) != NULL){

        if((saida.front)->valor != 8 && (saida.front)->valor != 6){
    	printf("%d", (saida.front)->valor );
    	check++;
    	
    	if((saida.front)->prox != NULL){
    	    printf(" ");	
    	}
        }
    	saida.front = (saida.front)->prox;
    }

    if(check != 0){
    	printf("8 6");
    }










//TESTES

    /*for(i=0; i<6; i++){
    	pilha_t1 = E1(pilha_t1, i);
    }
    for(i=0; i<3; i++){
    	saida = S1(pilha_t1, saida);
    	pilha_t1 = SE1(pilha_t1);
    }

    while(pilha_t1 != NULL){
    	printf("%d\n", pilha_t1->valor);
    	pilha_t1 = pilha_t1->prox;2
    }
    printf("\n\n\n");
    while((saida.front)!=NULL){
    	printf("%d\n", (saida.front)->valor);
    	saida.front = (saida.front)->prox;
    }*/
    
    /*

    for(i=0; i<10; i++){
    	term2 =E2E(term2, i);
    }
    //term2 = liberar_D(term2);
    //saida = S2D(term2, saida);
    //term2 = liberar_D(term2);

    saida = S2D(term2, saida);
    term2 = liberar_D(term2);
    
    saida = S1(term2.front, saida);
    term2.front = SE1(term2.front);

    saida = S1(term2.front, saida);
    term2.front = SE1(term2.front);

    saida = S2D(term2, saida);
    term2 = liberar_D(term2);

    saida = S1(term2.front, saida);
    term2.front = SE1(term2.front);

    saida = S2D(term2, saida);
    term2 = liberar_D(term2);

    saida = S1(term2.front, saida);
    term2.front = SE1(term2.front);   
    
    saida = S2D(term2, saida);
    term2 = liberar_D(term2);

    saida = S1(term2.front, saida);
    term2.front = SE1(term2.front); 
    
    saida = S1(term2.front, saida);
    term2.front = SE1(term2.front);
    





    

    while((term2.front) != NULL){
    	printf("%d %d\n", (term2.front)->valor, (term2.rear)->valor );
    	term2.front = (term2.front)->prox;
    }
    printf("\n\n\n");
    while((saida.front)!=NULL){
    	printf("%d ", (saida.front)->valor);
    	saida.front = (saida.front)->prox;
    }
    printf("\n"); */
    //printf("\n\n%d\n", (saida.front)->valor );
	

	return 0;
}