diff options
| author | _Tradam <[email protected]> | 2023-09-08 01:29:47 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-08 01:29:47 +0000 |
| commit | 3c76c7f3d5db3f9586a90d03f8fbb02d79de9acd (patch) | |
| tree | afbe4b540967223911f7c5de36559b82154f02f3 /misc/examples/list.c | |
| parent | 0841165881871ee01b782129be681209aeed2423 (diff) | |
| parent | 1a72205fe05c2375cfd380dd8381a8460d9ed8d1 (diff) | |
| download | STC-modified-modified.tar.gz STC-modified-modified.zip | |
Diffstat (limited to 'misc/examples/list.c')
| -rw-r--r-- | misc/examples/list.c | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/misc/examples/list.c b/misc/examples/list.c deleted file mode 100644 index 363d7fec..00000000 --- a/misc/examples/list.c +++ /dev/null @@ -1,63 +0,0 @@ -#include <stdio.h> -#include <time.h> -#include <stc/algo/filter.h> -#include <stc/crand.h> - -#define i_type DList -#define i_val double -#include <stc/clist.h> - -int main() { - const int n = 3000000; - DList list = {0}; - - crand_t rng = crand_init(1234567); - int m = 0; - c_forrange (n) - DList_push_back(&list, crand_f64(&rng)*n + 100), ++m; - - double sum = 0.0; - printf("sumarize %d:\n", m); - c_foreach (i, DList, list) - sum += *i.ref; - printf("sum %f\n\n", sum); - - c_forfilter (i, DList, list, c_flt_take(i, 10)) - printf("%8d: %10f\n", c_flt_getcount(i), *i.ref); - - puts("sort"); - DList_sort(&list); // qsort O(n*log n) - puts("sorted"); - - c_forfilter (i, DList, list, c_flt_take(i, 10)) - printf("%8d: %10f\n", c_flt_getcount(i), *i.ref); - puts(""); - - DList_drop(&list); - list = c_make(DList, {10, 20, 30, 40, 30, 50}); - - const double* v = DList_get(&list, 30); - printf("found: %f\n", *v); - - c_foreach (i, DList, list) - printf(" %g", *i.ref); - puts(""); - - DList_remove(&list, 30); - DList_insert_at(&list, DList_begin(&list), 5); // same as push_front() - DList_push_back(&list, 500); - DList_push_front(&list, 1964); - - printf("Full: "); - c_foreach (i, DList, list) - printf(" %g", *i.ref); - - printf("\nSubs: "); - DList_iter it = DList_begin(&list); - - c_foreach (i, DList, DList_advance(it, 4), DList_end(&list)) - printf(" %g", *i.ref); - puts(""); - - DList_drop(&list); -} |
