diff options
| author | Tyge Løvset <[email protected]> | 2023-01-03 10:37:44 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-01-03 10:37:44 +0100 |
| commit | c5abb5b806ddc3eedde2e6bcd31eef78c36edf33 (patch) | |
| tree | 70198361b1133d7c6eb930c998eaaf6888d13309 /misc/examples/sort.c | |
| parent | 16e004c62f8d8d502152a85b2ffd384a1c91a470 (diff) | |
| download | STC-modified-c5abb5b806ddc3eedde2e6bcd31eef78c36edf33.tar.gz STC-modified-c5abb5b806ddc3eedde2e6bcd31eef78c36edf33.zip | |
Fix compilation error in utf8code.c due to predeclaring a static array with unspecified size.
Diffstat (limited to 'misc/examples/sort.c')
| -rw-r--r-- | misc/examples/sort.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/misc/examples/sort.c b/misc/examples/sort.c index 65ae7359..ace1a6a4 100644 --- a/misc/examples/sort.c +++ b/misc/examples/sort.c @@ -1,39 +1,45 @@ -#include <stdio.h> #include <time.h> #include <stdlib.h> -#define i_val int +#include <stdio.h> #include <stc/crandom.h> -#include <stc/algo/csort.h> + +typedef float Elem; +#define fmt_Elem "%g" #ifdef __cplusplus -#include <algorithm> + #include <algorithm> +#else + #define i_val Elem + #include <stc/algo/csort.h> #endif -int testsort(csortval_int *a, size_t size, const char *desc) { +int testsort(Elem *a, size_t size, const char *desc) { clock_t t = clock(); #ifdef __cplusplus printf("std::sort: "); std::sort(a, a + size); #else printf("csort: "); - csort_int(a, size); + csort_Elem(a, size); #endif t = clock() - t; - printf("%s: %d elements sorted in %.3fms\n", + printf("%s: %d elements sorted in %.2f ms\n", desc, (int)size, t*1000.0/CLOCKS_PER_SEC); return 0; } int main(int argc, char *argv[]) { size_t i, size = argc > 1 ? strtoull(argv[1], NULL, 0) : 10000000; - csortval_int *a = (csortval_int*)malloc(sizeof(*a) * size); + Elem *a = (Elem*)malloc(sizeof(*a) * size); if (a == NULL) return -1; for (i = 0; i < size; i++) a[i] = crandom() & ((1U << 28) - 1); + testsort(a, size, "random"); - for (i = 0; i < 20; i++) printf(" %d", a[i]); + for (i = 0; i < 20; i++) + printf(" " fmt_Elem, a[i]); puts(""); testsort(a, size, "sorted"); |
