int verificaLivello(Albero* t1, Albero* t2, int lev) { lista * l1 = AllocaLista(t1, lev); lista * l2 = AllocaLista(t2, lev); printf("fine allocazioni\n"); printLista(l1); printLista(l2); return elementiInComune(l1, l2); }
int main() { int vetor[MAX], vetor2[MAX]; node *lista = NULL, *lista2 = NULL; clock_t start, stop; printf("Preenchendo vetor e lista com números aleatórios...\n"); preencheVetor(vetor, MAX); printf("Vetor\n"); printVetor(vetor, MAX); preencheLista(&lista, MAX); printf("Lista\n"); printLista(lista); printf("Iniciando insertionSort em vetor...\n"); start = clock(); insertionSortVetor(vetor, MAX); stop = clock(); printf("insertionSort em vetor concluído!\n"); printVetor(vetor, MAX); printf("Tempo decorrido: %lf segundos.\n", ((double)(stop - start) / CLOCKS_PER_SEC)); printf("Iniciando insertionSort em lista...\n"); start = clock(); insertionSortLista(lista); stop = clock(); printf("insertionSort em lista concluído!\n"); printLista(lista); printf("Tempo decorrido: %lf segundos.\n", ((double)(stop - start) / CLOCKS_PER_SEC)); printf("Preenchendo vetor2 e lista2 com números aleatórios...\n"); preencheVetor(vetor2, MAX); printf("Vetor 2\n"); printVetor(vetor2, MAX); preencheLista(&lista2, MAX); printf("Lista 2\n"); printLista(lista2); printf("Iniciando bubbleSort em vetor 2...\n"); start = clock(); bubbleSortVetor(vetor, MAX); stop = clock(); printf("bubbleSort em vetor 2 concluído!\n"); printVetor(vetor, MAX); printf("Tempo decorrido: %lf segundos.\n", ((double)(stop - start) / CLOCKS_PER_SEC)); printf("Iniciando bubbleSort em lista 2...\n"); start = clock(); bubbleSortLista(lista); stop = clock(); printf("bubbleSort em lista 2 concluído!\n"); printLista(lista); printf("Tempo decorrido: %lf segundos.\n", ((double)(stop - start) / CLOCKS_PER_SEC)); return 0; }
int main() { printf("inizio\n"); Albero* myalbero=NULL; addNodo(&myalbero, 15); addNodo(&myalbero, 10); addNodo(&myalbero, 8); addNodo(&myalbero, 5); addNodo(&myalbero, 9); addNodo(&myalbero, 25); addNodo(&myalbero, 19); addNodo(&myalbero, 29); printf("fine inserimento\n"); lista* l1 = AllocaLista(myalbero, 1); printf("fine allocalista\n"); printLista(l1); Albero* myalbero2=NULL; addNodo(&myalbero2, 15); addNodo(&myalbero2, 10); addNodo(&myalbero2, 8); addNodo(&myalbero2, 5); addNodo(&myalbero2, 9); addNodo(&myalbero2, 25); addNodo(&myalbero2, 19); addNodo(&myalbero2, 29); addNodo(&myalbero2, 28); addNodo(&myalbero2, 31); // printf("verificalivelli: %d",verificaLivello(myalbero, myalbero2, 3)); printf("\n\nfine Programma\n"); ModificaFile(myalbero,"livelli.txt"); return 0; }
int main() { int i, escolhido, repetir; node *lista; do { lista = NULL; printf("Ha' 15 numeros na lista.\n"); for(i = 0; i < 15; i++) { addNum(&lista, i + 1); } printf("Sua lista: \n"); printLista(lista); printf("\nDe qual vc vai remover os vizinhos? "); scanf("%d", &escolhido); removerVizinhos(&lista, escolhido); printf("\nSua nova lista: \n"); printLista(lista); printf("\n\nDeseja repetir? Aperte 1 - SIM, qualquer outro - NAO: "); scanf("%d", &repetir); printf("\n"); freeLista(&lista); }while(repetir == 1); printf("Acabou-se.\n"); return 0; }
int main(){ int fn,size; TpContato *tp = start(); ListaContato *lista = init(), *lista_copy=init(), *lista_aux=init(); TpContato *aux = start(), *copy = aux; clock_t cinicio, cfinal; system("clear"); do{ printf( "Escolha uma das opções abaixo:\n" "\t1) Criar Lista\n" "\t2) Cirar Vetor\n" "\t3) Ordenacao com Comb Sort\n" "\t4) Ordenacao com Merge Sort\n" "\t5) Sair\n\n" ); scanf(" %d",&fn); switch(fn){ case 1: system("clear"); printf("Criar lista com quantos elementos?\n"); scanf(" %d", &size); lista = createLista(size); printLista(lista); break; case 2: system("clear"); printf("\t2) Cirar Vetor\n"); tp = createVetor(); fillVetor(tp); printVetor(tp); break; case 3: system("clear"); printf("\t3) Ordenacao com Comb Sort\n"); if (!isEmpty_vetor(tp)){ copy = createVetor(); vetcpy(copy, tp); cinicio = clock(); combSort_vetor(copy); cfinal = clock(); printf("\n"); printVetor(copy); printf("Tempo: %f segundos.\n", (float)(cfinal-cinicio)/CLOCKS_PER_SEC); if(!isEmpty_vetor(copy)) free(copy); } if (!isEmpty_lista(lista)){ lista_copy = listacpy(lista); cinicio = clock(); combSort_lista(lista_copy,size); cfinal = clock(); printf("\n"); printLista(lista_copy); printf("Tempo: %f segundos.\n", (float)(cfinal-cinicio)/CLOCKS_PER_SEC); lista_copy = ourFree(lista_copy); } break; case 4: system("clear"); printf("\t4) Ordenacao com Merge Sort\n"); if (!isEmpty_vetor(tp)){ aux = createVetor(); copy = createVetor(); vetcpy(copy, tp); cinicio = clock(); mergeSort(copy, 0, MAX-1, aux); // Vetor vai de 0-39 cfinal = clock(); printf("\n"); printVetor(copy); printf("Tempo: %f segundos.\n", (float)(cfinal-cinicio)/CLOCKS_PER_SEC); if (!isEmpty_vetor(aux)) free(aux); // Liberando memória if (!isEmpty_vetor(copy)) free(copy); // Liberando memória } if (!isEmpty_lista(lista)){ lista_copy = listacpy(lista); cinicio = clock(); lista_aux = mergeSortList(lista_copy, 0, size-1, lista_aux); cfinal = clock(); printf("\n"); printLista(lista_copy); printf("Tempo: %f segundos.\n", (float)(cfinal-cinicio)/CLOCKS_PER_SEC); lista_copy = ourFree(lista_copy); lista_aux = ourFree(lista_aux); } break; case 5: system("clear"); printf("BYE!\n\n"); break; default: system("clear"); printf("Opção invalida!\n"); break; } }while(fn != 5); if (!isEmpty_vetor(tp)) free(tp); lista = ourFree(lista); return 0; }
int main(){ char op; Lista* listaAlunos = NULL; Arvore* ArvoreCodigo = NULL; Arvore* ArvoreNome = NULL; Arvore* ArvoreMedia = NULL; ///* listaAlunos = addL(listaAlunos, 5, "ADeise\n", 8.2); listaAlunos = addL(listaAlunos, 1, "BMaria\n", 6.1); listaAlunos = addL(listaAlunos, 10, "DJoao\n", 4.9); listaAlunos = addL(listaAlunos, 12, "CPaulo\n", 5.8); do{ system("cls"); printf("Digite: \n"); printf("1 - Adicionar alunos;\n"); printf("2 - Remover alunos;\n"); printf("3 - Mostrar lista de alunos;\n"); printf("4 - Mostrar arvore ordenada por codigo;\n"); printf("5 - Mostrar arvore ordenada por nome;\n"); printf("6 - Mostrar arvore ordenada por media\n"); printf("0 - Sair\n\n"); op = getch(); switch(op){ case '1': listaAlunos = adicionar_aluno(listaAlunos); break; case '2': listaAlunos = remover_aluno(listaAlunos); break; case '3': printLista(listaAlunos); break; case '4': ArvoreCodigo = atualizarArvoreDeCodigo(ArvoreCodigo, listaAlunos); system("cls"); printf("Arvore ordenada por codigo:\n\n\n"); printArvore(ArvoreCodigo); system("pause"); break; case '5': ArvoreNome = atualizarArvoreDeNome(ArvoreNome, listaAlunos); system("cls"); printf("Arvore ordenada por nome:\n\n\n"); printArvore(ArvoreNome); system("pause"); break; case '6': ArvoreMedia = atualizarArvoreDeMedia(ArvoreMedia, listaAlunos); system("cls"); printf("Arvore ordenada por media:\n\n\n"); printArvore(ArvoreMedia); system("pause"); break; } } while(op != '0'); //*/ return 0; }