summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/list.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-02-17 10:21:30 +0100
committerTyge Løvset <[email protected]>2023-02-17 14:50:58 +0100
commitc4ae61de5be08e719e3183f4e2d1115c11856796 (patch)
tree2fe6f4c44fc6189db4dcf3b0d65ca44fbff4fac2 /misc/examples/list.c
parent8864c11b2b85f832ce746a902b43ecf170e2eebc (diff)
downloadSTC-modified-c4ae61de5be08e719e3183f4e2d1115c11856796.tar.gz
STC-modified-c4ae61de5be08e719e3183f4e2d1115c11856796.zip
Improved clist: 1) added clist_X_sort_with(self, cmp) - custom compare func. 2) shortened mergesort function.
Diffstat (limited to 'misc/examples/list.c')
-rw-r--r--misc/examples/list.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/misc/examples/list.c b/misc/examples/list.c
index 1eb58802..79dcfcaf 100644
--- a/misc/examples/list.c
+++ b/misc/examples/list.c
@@ -8,7 +8,7 @@
#include <stc/crandom.h>
int main() {
- const int n = 2000000;
+ const int n = 1000000;
c_auto (clist_fx, list)
{
@@ -30,6 +30,12 @@ int main() {
clist_fx_sort(&list); // mergesort O(n*log n)
puts("sorted");
+ int last = 0;
+ c_foreach (i, clist_fx, list) {
+ if (*i.ref < last) {printf("ERROR"); exit(-1);}
+ last = *i.ref;
+ }
+
c_forwhile (i, clist_fx, clist_fx_begin(&list), i.index < 10)
printf("%8d: %10f\n", (int)i.index, *i.ref);
puts("");