summaryrefslogtreecommitdiff
path: root/gsl-1.9/doc/examples/sortsmall.c
diff options
context:
space:
mode:
Diffstat (limited to 'gsl-1.9/doc/examples/sortsmall.c')
-rw-r--r--gsl-1.9/doc/examples/sortsmall.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/gsl-1.9/doc/examples/sortsmall.c b/gsl-1.9/doc/examples/sortsmall.c
new file mode 100644
index 0000000..5b72517
--- /dev/null
+++ b/gsl-1.9/doc/examples/sortsmall.c
@@ -0,0 +1,38 @@
+#include <gsl/gsl_rng.h>
+#include <gsl/gsl_sort_double.h>
+
+int
+main (void)
+{
+ const gsl_rng_type * T;
+ gsl_rng * r;
+
+ size_t i, k = 5, N = 100000;
+
+ double * x = malloc (N * sizeof(double));
+ double * small = malloc (k * sizeof(double));
+
+ gsl_rng_env_setup();
+
+ T = gsl_rng_default;
+ r = gsl_rng_alloc (T);
+
+ for (i = 0; i < N; i++)
+ {
+ x[i] = gsl_rng_uniform(r);
+ }
+
+ gsl_sort_smallest (small, k, x, 1, N);
+
+ printf ("%d smallest values from %d\n", k, N);
+
+ for (i = 0; i < k; i++)
+ {
+ printf ("%d: %.18f\n", i, small[i]);
+ }
+
+ free (x);
+ free (small);
+ gsl_rng_free (r);
+ return 0;
+}