summaryrefslogtreecommitdiffhomepage
path: root/examples/list.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/list.c')
-rw-r--r--examples/list.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/examples/list.c b/examples/list.c
index a65a8454..bf777611 100644
--- a/examples/list.c
+++ b/examples/list.c
@@ -5,25 +5,25 @@
declare_clist(fx, double);
int main() {
+ int k, n = 100000;
clist_fx list = clist_init;
crand_eng64_t eng = crand_eng64_init(time(NULL));
- crand_uniform_f64_t dist = crand_uniform_f64_init(1.0, 100.0);
- int n;
- for (int i = 0; i < 10000000; ++i) // ten million
+ crand_uniform_f64_t dist = crand_uniform_f64_init(0.0f, n);
+
+ for (int i = 0; i < 100000; ++i)
clist_fx_push_back(&list, crand_uniform_f64(&eng, dist));
- n = 100;
- c_foreach (i, clist_fx, list)
- if (n--) printf("%8d: %10f\n", 100 - n, i.item->value); else break;
- // Sort them...
+ k = 0; c_foreach (i, clist_fx, list)
+ if (++k <= 10) printf("%8d: %10f\n", k, i.item->value); else break;
+
clist_fx_sort(&list); // mergesort O(n*log n)
- n = 100;
puts("sorted");
- c_foreach (i, clist_fx, list)
- if (n--) printf("%8d: %10f\n", 100 - n, i.item->value); else break;
+
+ k = 0; c_foreach (i, clist_fx, list)
+ if (++k <= 10) printf("%8d: %10f\n", k, i.item->value); else break;
clist_fx_clear(&list);
c_push(&list, clist_fx, c_items(10, 20, 30, 40, 50));
- c_foreach (i, clist_fx, list) printf("%f ", i.item->value);
+ c_foreach (i, clist_fx, list) printf("%.1f ", i.item->value);
puts("");
clist_fx_destroy(&list);