add cleanup

This commit is contained in:
Chris Cromer 2018-11-11 18:07:23 -03:00
parent 8d4e695bec
commit 0d2d59e84b
Signed by: cromer
GPG Key ID: 39CC813FF3C8708A
1 changed files with 9 additions and 3 deletions

View File

@ -22,6 +22,8 @@
#define SORT_VERSION "1.0.0"
static int *array;
/**
* Imprimir el uso del programa
*/
@ -59,6 +61,10 @@ void print_array(int *array, int n) {
fprintf(stdout, "\n");
}
void cleanup() {
free(array);
}
/**
* La entrada del programa
* @param argc La cantidad de argumentos pasado al programa
@ -152,7 +158,8 @@ int main (int argc, char **argv) {
}
}
int *array = malloc(sizeof(int) * n);
array = malloc(sizeof(int) * n);
atexit(cleanup);
// Llenar el array con valores para ordenar después
for (i = 0; i < n; i++) {
@ -184,6 +191,7 @@ int main (int argc, char **argv) {
// quick sort
}
else if (algoritmo == 2) {
fprintf(stdout, "Bubble sort corriendo...\n");
start_timer();
bubble_sort(array, n);
stop_timer();
@ -208,8 +216,6 @@ int main (int argc, char **argv) {
print_array(array, n);
}
free(array);
print_timer();
return 0;
}