-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestao3.c
75 lines (63 loc) · 2.64 KB
/
questao3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "sort.h"
#include "utils.h"
void main(){
int vectors_length = 500000;
printf("Creating first vector...\n");
int *vector1 = (int *) malloc(vectors_length * sizeof(int));
printf("Creating second vector...\n");
int *vector2 = (int *) malloc(vectors_length * sizeof(int));
printf("Creating third vector...\n");
int *vector3 = (int *) malloc(vectors_length * sizeof(int));
printf("Creating fourth vector...\n");
int *vector4 = (int *) malloc(vectors_length * sizeof(int));
/* Variáveis pra armazenar quando os algoritmos de ordenação começam
e terminam
*/
long start_time, end_time;
/*Executa 3 vezes cada algoritmo de ordenção, cada vez com um vetor
distinto
*/
for(int vector_time = 1; vector_time <= 3; vector_time++){
printf("\n --- VECTOR NUMBER: %d ----------------\n", vector_time);
//Preenche todos os vetores com a mesma sequência de números aleatórios
printf("Filling vector with random numbers...\n");
fillRandomVector(vector1, vectors_length, 0, 100);
printf("Filling vector with random numbers...\n");
copyVector(vector1, vector2, vectors_length);
printf("Filling vector with random numbers...\n");
copyVector(vector1, vector3, vectors_length);
printf("Filling vector with random numbers...\n");
copyVector(vector1, vector4, vectors_length);
/*Em ordem:
1 - Marca o tempo inicial;
2 - Ordena o vetor;
3 - Marca o tempo final;
4 - Exibe o tempo decorrido na ordenação.
Procedimento recorrente para os 4 algoritmos.
*/
printf("\n-- SELECTION SORT SECTION --\n");
printf("Sorting vector...\n");
start_time = time(NULL);
selectionSort(vector1, vectors_length);
end_time = time(NULL);
printf("Time: %ld s.\n", (end_time-start_time));
printf("\n-- INSERTION SORT SECTION --\n");
printf("Sorting vector...\n");
start_time = time(NULL);
insertionSort(vector2,vectors_length);
end_time = time(NULL);
printf("Time: %ld s.\n", (end_time-start_time));
printf("\n-- MERGE SORT SECTION --\n");
printf("Sorting vector...\n");
start_time = time(NULL);
mergesort(vector3, 0, vectors_length - 1);
end_time = time(NULL);
printf("Time: %ld s.\n", (end_time-start_time));
printf("\n-- QUICK SORT SECTION --\n");
start_time = time(NULL);
quicksort(vector4, 0, vectors_length - 1);
end_time = time(NULL);
printf("Time: %ld s.\n", (end_time-start_time));
}
printf("\n");
}