Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void avl_max_subarvore(arvore_avl *arv, const char *inicio) {
- /* prob 1.1 - a implementar */
- if ((arv || inicio) == NULL)
- return;
- no_avl *raizsub;
- raizsub = avl_pesquisa(arv, inicio);
- while ((raizsub->direita) != NULL) {
- raizsub = raizsub->direita;
- }
- printf("%s", raizsub->str);
- }
- tabela_dispersao* tabela_copia(tabela_dispersao *original, int novotamanho) {
- /* prob 1.2 - a implementar */
- if ((original == NULL) || (novotamanho == NULL) || (novotamanho == 0))
- return NULL;
- int i;
- tabela_dispersao *tabnova;
- tabnova = tabela_nova(novotamanho, original->hfunc);
- for (i = 0; i < original->tamanho; i++) {
- if (original->elementos[i]) {
- tabela_adiciona(tabnova, original->elementos[i]->obj->chave,
- original->elementos[i]->obj->valor);
- }
- }
- return tabnova;
- }
- int proximas_n_chegadas(lista *tempos, lista *origens, lista *aeroportos, int n) {
- /* prob 2.1 - a implementar */
- if (tempos == NULL || origens == NULL || aeroportos == NULL)
- return 0;
- if (n == 0)
- return 0;
- int i, prioridade, j, k, indice;
- heap *hp;
- hp = heap_nova(25);
- elemento *tempo, *aux, *aux3;
- tempo = tempos->inicio;
- aux = origens->inicio;
- aux3 = aeroportos->inicio;
- char *aux2;
- for (i = 0; i < lista_tamanho(tempos); i++) {
- prioridade = atoi(tempo->str);
- tempo = tempo->proximo;
- heap_insere(hp, aux->str, prioridade);
- aux = aux->proximo;
- }
- // mostraHeap(hp, 0); // hp tem string de ints com cod do aeroporto e está organizada com prioridade de menor tempo
- for (j = 0; j < n; j++) {
- aux2 = heap_remove(hp);
- indice = atoi(aux2);
- aux3 = aeroportos->inicio;
- for (k = 0; k < indice; k++)
- aux3 = aux3->proximo;
- printf("%i : %s\n", j + 1, aux3->str);
- }
- return 1;
- }
- lista* pesquisa_destinos(grafo *rotas, lista *aeroportos, const char *origem) {
- /* prob 2.2 - a implementar */
- if (rotas == NULL || origem == NULL || aeroportos == NULL)
- return NULL;
- int i, k, l, j, z;
- elemento *aux, *aux2;
- aux = aeroportos->inicio;
- vetor *vec;
- vec = vetor_novo();
- lista *ls;
- ls = lista_nova();
- for (i = 0; i < lista_tamanho(aeroportos); i++) {
- if (strcmp(origem, aux->str) == 0) //encontrou o aeroporto
- break;
- aux = aux->proximo;
- }
- //Encontrou o indice de Lille
- //printf("%i\n", i);
- vec = v_sucessores(rotas, i);
- //printf("%i\n", vetor_tamanho(vec));
- for (k = 0; k < vetor_tamanho(vec); k++) {
- aux = aeroportos->inicio;
- j = vec->elementos[k].val;
- for (l = 0; l < j; l++) {
- aux = aux->proximo;
- }
- lista_insere(ls, aux->str, NULL);
- }
- z = lista_ordena(ls);
- if (z == 0)
- return ls;
- else
- NULL;
- }
- ------------------- Teste exemplo 2
- void avl_imprime_ord(arvore_avl* avl, int ordem) {
- /* prob 1.1 - a implementar */
- no_avl *aux;
- //CRESCENTE
- if (ordem >= 0) {
- while (avl->raiz != NULL) {
- aux = avl->raiz;
- while (aux->esquerda != NULL)
- aux = aux->esquerda;
- printf("%s ", aux->str);
- avl_remove(avl, aux->str);
- }
- }
- //DECRESCENTE
- else if (ordem >= 0) {
- while (avl->raiz != NULL) {
- aux = avl->raiz;
- while (aux->direita != NULL)
- aux = aux->direita;
- printf("%s ", aux->str);
- avl_remove(avl, aux->str);
- }
- }
- }
- void valida_passwds(FILE *f, lista *login, lista *passwd) {
- /* prob 1.2 - a implementar */
- tabela_dispersao *td;
- td = tabela_nova(10, hash_djbm);
- const char delimitador1[] = " ", delimitador2[] = "\n";
- char string[50];
- char *user, *pw;
- int i;
- while ((fgets(string, 50, f)) != NULL) {
- string[strlen(string) - 1] = '\0';
- user = strtok(string, delimitador1);
- pw = strtok(NULL, delimitador2);
- tabela_adiciona(td, user, pw);
- }
- //mostraTabela(td);
- elemento *aux1, *aux2;
- aux1 = login->inicio;
- aux2 = passwd->inicio;
- char *aux3;
- int z;
- for (i = 0; i < (login->tamanho); i++) {
- printf("Login: %s\n", aux1->str);
- printf("Password: %s\n", aux2->str);
- aux3 = tabela_valor(td, aux1->str);
- z = tabela_existe(td, aux2->str);
- if (z == 0) {
- printf("Sucesso\n");
- }
- else
- printf("Insucesso\n");
- aux1 = aux1->proximo;
- aux2 = aux2->proximo;
- }
- }
- lista* descobre_caminho(grafo *g, int origem, int destino, int obrigatorio) {
- /* prob 2.1 - a implementar */
- int *parte1, *parte2;
- int tamcam1, tamcam2, i;
- lista *ls;
- ls = lista_nova();
- char str[2];
- parte1 = grafo_bfs(g, origem, obrigatorio, &tamcam1);
- if (parte1 == 0 || parte1 == NULL)
- return NULL;
- parte2 = grafo_bfs(g, obrigatorio, destino, &tamcam2);
- if (parte2 == 0 || parte2 == NULL)
- return NULL;
- for (i = 0; i < tamcam1; i++) {
- sprintf(str, "%i", *(parte1 + i));
- lista_insere(ls, str, -1);
- }
- for (i = 0; i < tamcam2 - 1; i++) {
- sprintf(str, "%i", *(parte2 + i));
- lista_insere(ls, str, -1);
- }
- return ls;
- }
- int simula_acontecimentos(lista *acoes, lista *tempos, int n) {
- /* prob 2.2 - a implementar */
- heap *hp;
- hp = heap_nova(20);
- int i, j;
- elemento_lista *aux1, *aux2;
- aux1 = acoes->raiz;
- aux2 = tempos->raiz;
- char *str;
- for (i = 0; i < lista_tamanho(tempos); i++) {
- heap_insere(hp, aux1->str, (atoi(aux2->str)));
- aux1 = aux1->proximo;
- aux2 = aux2->proximo;
- }
- for (j = 1; j <= n; j++) {
- str = heap_remove(hp);
- printf("%i : %s\n", j, str);
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement