示例#1
0
文件: maxIndsoOn.c 项目: Jessycah/C
int main(){
	int N=7;
	int v[7]={1,9,8,5,4,3,2};
	int i;
	printVetor(v,N);
	ordena(v,N);
	printVetor(v,N);
	return 1;
}
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;
}
示例#3
0
int main() {
    int v[TAMX][TAMY];
    int i = 0;
    int j = 0;

    for(i = 0; i < TAMX; i++) {
        for(j = 0; j < TAMY; j++) {
            if(i % 2) 
                v[i][j] = (i * j) / (j + i);
            else
                v[i][j] = j * i;
        }
    }
    
    for(i = 0; i < TAMX; i++) {
        for(j = 0; j < TAMY; j++) {
            printf("%4d, ", v[i][j]);
        }
        printf("\n");
    }
    
    printf("\n");

    printVetor(*v);

    return 0;
}
示例#4
0
文件: main.c 项目: WDayan/LastWork
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;
}