implement divide and conquer
This commit is contained in:
19
src/points.c
19
src/points.c
@@ -18,6 +18,7 @@
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include "points.h"
|
||||
#include "distance.h"
|
||||
#include "timer.h"
|
||||
@@ -166,26 +167,18 @@ int main (int argc, char **argv) {
|
||||
end_algorithm();
|
||||
fprintf(stdout, "point 1: x: %f y: %f\n", closest_points[0].x, closest_points[0].y);
|
||||
fprintf(stdout, "point 2: x: %f y: %f\n", closest_points[1].x, closest_points[1].y);
|
||||
fprintf(stdout, "distance: %lf\n\n", dist);
|
||||
fprintf(stdout, "distance: %lf\n\n", sqrt(dist));
|
||||
free(closest_points);
|
||||
closest_points = NULL;
|
||||
}
|
||||
|
||||
if (divide) {
|
||||
if (n <= 3) {
|
||||
fprintf(stderr, "Divide and conquer necesita 4 o mas puntos!\nSe utilizará Brute Force como alternativa!\n");
|
||||
start_algorithm("Brute force corriendo... ", n);
|
||||
closest_points = brute_force(points, n, &dist);
|
||||
end_algorithm();
|
||||
}
|
||||
else {
|
||||
start_algorithm("Divide and conquer corriendo... ", n);
|
||||
closest_points = divide_and_conquer(points, n, &dist);
|
||||
end_algorithm();
|
||||
}
|
||||
start_algorithm("Divide and conquer corriendo... ", n);
|
||||
closest_points = divide_and_conquer(points, n, &dist);
|
||||
end_algorithm();
|
||||
fprintf(stdout, "point 1: x: %f y: %f\n", closest_points[0].x, closest_points[0].y);
|
||||
fprintf(stdout, "point 2: x: %f y: %f\n", closest_points[1].x, closest_points[1].y);
|
||||
fprintf(stdout, "distance: %lf\n", dist);
|
||||
fprintf(stdout, "distance: %lf\n", sqrt(dist));
|
||||
free(closest_points);
|
||||
closest_points = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user