-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgnome.c
More file actions
49 lines (40 loc) · 1.03 KB
/
Copy pathgnome.c
File metadata and controls
49 lines (40 loc) · 1.03 KB
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
#include <stdio.h>
#include <string.h>
#include <time.h>
void gnomeSort(char *array[], int n){
int pos = 0;
while(pos < n){
if (pos == 0 || strcmp(array[pos], array[pos-1]) >= 0){
pos++;
}
else{
char *temp = array[pos];
array[pos] = array[pos - 1];
array[pos - 1] = temp;
pos--;
}
}
}
int main(void){
clock_t inicio, fim;
double tempo_execucao;
char *array[] = {"Debora", "Armando", "Angela", "Fernanda"};
int n = sizeof(array) / sizeof(array[0]);
inicio = clock();
printf("%d\n", n);
printf("Vetor original:\n");
for(int i = 0; i < n; i++){
printf("%s\n", array[i]);
}
printf("\n");
gnomeSort(array, n);
printf("Vetor ordenado:\n");
for(int i = 0; i < n; i++){
printf("%s\n", array[i]);
}
printf("\n");
fim = clock();
tempo_execucao = (double)(fim - inicio) / CLOCKS_PER_SEC;
printf("Tempo de execução: %.5f segundos\n", tempo_execucao);
return 0;
}