Pilha* empilharExpressaoOperador(Pilha* p, char* operador){ if(tamanhoPilha(p) > 1){ Arvore* primeiro, *segundo; Pilha* pilha; primeiro = getArvoreTopoPilha(p); p = desempilhar(p); segundo = getArvoreTopoPilha(p); p = desempilhar(p); Arvore* arvoreOperador = inicializaArvore(TIPO_LITERAL, operador, NULL, NULL); arvoreOperador = setFilhosEsquerdaCentroDireita(arvoreOperador, primeiro, segundo, NULL); p = empilhar(p, arvoreOperador); } return p; }
int main ( void ){ inicializaArvore(); //deve funcionar para as proximas funções funcionarem. createHeader(); //para as funçoes funcionarem o header deve ser criado, se o header foi criado então a função está correta CU_pSuite pSuite = NULL; /* initialize the CUnit test registry */ if ( CUE_SUCCESS != CU_initialize_registry() ) return CU_get_error(); /* add a suite to the registry */ pSuite = CU_add_suite( "max_test_suite", init_suite, clean_suite ); if ( NULL == pSuite ) { CU_cleanup_registry(); return CU_get_error(); } /* add the tests to the suite */ if ( (NULL == CU_add_test(pSuite, "Inserir", test_insere)) || (NULL == CU_add_test(pSuite, "atualizar", test_atualiza)) || (NULL == CU_add_test(pSuite, "excluir", test_exclui)) ) { CU_cleanup_registry(); return CU_get_error(); } // Run all tests using the basic interface CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_run_tests(); printf("\n"); CU_basic_show_failures(CU_get_failure_list()); printf("\n\n"); /* // Run all tests using the automated interface CU_automated_run_tests(); CU_list_tests_to_file(); // Run all tests using the console interface CU_console_run_tests(); */ /* Clean up registry and return */ CU_cleanup_registry(); return CU_get_error(); }
Pilha* empilharElementoCriandoArvore(Pilha* p, int tipo, void* valorNo){ Arvore* a = inicializaArvore(tipo, valorNo, NULL, NULL); p = empilhar(p, a); return p; }
int main(int argc, char *argv[]){ FILE *arquivo1, *arquivo2; Parvore arvore; PLista lista, lista2, lista3, p, z, y; char carac_text, carac_dicio; char word[2000000]; char word_text[2000000]; char other_word[2000000]; int i = 0, tam = 0, j = 0, lines = 1, k; inicializaArvore(&arvore); inicializaLista(&lista); inicializaLista(&lista2); inicializaLista(&lista3); arquivo1 = fopen(argv[1], "r"); arquivo2 = fopen(argv[2], "r"); //PEGANDO TODAS AS PALAVRAS DO DICIONARIO E INSERINDO NA ARVORE TRIE while((carac_dicio = fgetc(arquivo1)) != EOF){ if(carac_dicio != '\n'){ word[i] = carac_dicio; i++; } else{ word[i] = '\0'; i = 0; inserir_palavra(&arvore, strlen(word), word); } } //LENDO E TRATANDO TODOS OS CARACTERES DO ARQUIVO2 while((carac_text = fgetc(arquivo2)) != EOF) tam++; //criando string com todo o conteudo do texto char string[tam]; rewind(arquivo2); i = 0; while((carac_text = fgetc(arquivo2)) != EOF){ string[i] = carac_text; i++; } string[i] = '\0'; //o texto todo esta nessa string i = 0; for(j = 0; j < tam; j++){ if((seekChar(separadores,string[j])) && (i == 0)){ //j++; continue; } if(seekChar(separadores, string[j])){ word_text[i] = '\0'; strcpy(other_word,word_text); i = 0; for(k = 0; k < strlen(word_text); k++) word_text[k] = tolower(word_text[k]); if(buscar_palavra(arvore, word_text) == 1){ inserir_crescente(&lista, word_text); } else{ inserir_final(&lista2, other_word); } } else{ word_text[i] = string[j]; i++; } } i = 0; for(p = lista; (p != NULL); p = p->prox){ int aux = 1; int number; printf("%s", p->palavra); for(j = 0; j < tam; j++){ if(seekChar(separadores, string[j])){ word_text[i] = '\0'; i = 0; for(k = 0; k < strlen(word_text); k++) word_text[k] = tolower(word_text[k]); if((strcmp(word_text,p->palavra)) == 0){ if (lines != number){ if(aux == 1){ printf(" %d", lines); number = lines; } else{ printf(", %d", lines); number = lines; } aux = 0; } } if(string[j] == '\n'){ lines++; number = lines-1; } } else{ word_text[i] = string[j]; i++; } } printf("\n"); lines = 1; } //imprimir(lista2); for(z = lista2; (z != NULL); z = z->prox){ printf("%s ", z->palavra); //for(y = lista3; (y != NULL); y = y->prox){ buscarMenor(arvore, z->palavra); printf("%s\n", menorpalavra); menorpalavra[0] = '\0'; menor = 100; } }