Add bubble sort #8

Merged
cromer merged 16 commits from bubblesort into master 2018-11-11 19:17:20 -03:00
2 changed files with 23 additions and 1 deletions
Showing only changes of commit 051f6b75e0 - Show all commits

View File

@ -18,4 +18,5 @@
void start_timer();
void stop_timer();
void print_timer();
long int get_timer();
#endif

View File

@ -15,13 +15,20 @@
#include <stdio.h>
#include <time.h>
#include "timer.h"
/**
* El tiempo que demoró en ejecutar algo
* Cuando empezó el timer
*/
static time_t start_time = 0;
/**
* Cuando terminó el timer
*/
static time_t stop_time = 0;
/**
* Empezar el timer
*/
void start_timer() {
if (start_time != 0) {
fprintf(stderr, "Error: El temporizador ya comenzó!\n");
@ -32,6 +39,9 @@ void start_timer() {
}
}
/**
* Terminar el timer
*/
void stop_timer() {
if (start_time == 0) {
fprintf(stderr, "Error: El temporizador no ha comenzado todavía!\n");
@ -41,6 +51,17 @@ void stop_timer() {
}
}
/**
* Imprimir el tiempo de ejecución
*/
void print_timer() {
fprintf(stdout, "Tiempo de ejecución: %ld segundos\n", (long int) (stop_time - start_time));
}
/**
* Devolver el tiempo que demoró en ejecutarse
* @return El tiempo que demoró
*/
long int get_timer() {
return (long int) (stop_time - start_time);
}