Closest-pair problem/C: Difference between revisions

m
Fixed syntax highlighting.
(replaced code)
m (Fixed syntax highlighting.)
 
(One intermediate revision by one other user not shown)
Line 1:
{{collection|Closest pair problem}}
 
<langsyntaxhighlight Clang="c">#include <stdio.h>
#include <stdlib.h>
#include <values.h>
Line 21:
 
int cmp_x(const void *a, const void *b) {
return cmp_dbl( (*((const point*)a))->x, (*((const point*)b))->x );
}
 
int cmp_y(const void *a, const void *b) {
return cmp_dbl( (*((const point*)a))->y, (*((const point*)b))->y );
}
 
Line 137:
/* not freeing the memory, let OS deal with it. Habit. */
return 0;
}</langsyntaxhighlight>Compile and run (1000000 points, bruteforce method not shown because it takes forever):<langpre>
% gcc -Wall -lm -O2 test.c
% time ./a.out
min: 5.6321e-05; point (19.657247,79.900855) and (19.657303,79.900862)
./a.out 7.16s user 0.08s system 96% cpu 7.480 total
</langpre>
9,476

edits