diff options
| author | Tyge Løvset <[email protected]> | 2022-04-25 11:54:07 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-04-25 11:54:07 +0200 |
| commit | 09f08e7ac65624d63f1eb04fba2317a2e0b2b0b7 (patch) | |
| tree | c21f2050aa71bd61e8ceec2a2cf39e98ed0eb1c8 /examples | |
| parent | 75eade4cef3219618cf0b88795660d2d16db2cda (diff) | |
| download | STC-modified-09f08e7ac65624d63f1eb04fba2317a2e0b2b0b7.tar.gz STC-modified-09f08e7ac65624d63f1eb04fba2317a2e0b2b0b7.zip | |
Added lower_bound() examples with both sorted cvec and sorted set (csset).
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/lower_bound.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/examples/lower_bound.c b/examples/lower_bound.c new file mode 100644 index 00000000..578209f8 --- /dev/null +++ b/examples/lower_bound.c @@ -0,0 +1,47 @@ +#include <stdio.h>
+
+#define i_val int
+#include <stc/cvec.h>
+
+#define i_val int
+#include <stc/csset.h>
+
+
+int main()
+{
+ c_auto (csset_int, set)
+ c_auto (cvec_int, vec)
+ {
+ int key, *res;
+
+ // TEST SORTED VECTOR
+ c_apply(t, cvec_int_push(&vec, t), int, {
+ 40, 600, 1, 7000, 2, 500, 30,
+ });
+
+ cvec_int_sort(&vec);
+
+ key = 550;
+ res = cvec_int_lower_bound(&vec, key).ref;
+
+ if (res != cvec_int_end(&vec).ref)
+ printf("Vec key %d: lower bound: %d\n", key, *res); // 600
+ else
+ printf("Vec element not found\n");
+
+
+ // TEST SORTED SET
+ c_apply(t, csset_int_push(&set, t), int, {
+ 40, 600, 1, 7000, 2, 500, 30,
+ });
+
+ key = 550;
+ res = csset_int_lower_bound(&set, key).ref;
+
+ if (res != csset_int_end(&set).ref)
+ printf("Set key %d: lower bound: %d\n", key, *res); // 600
+ else
+ printf("Set element not found\n");
+ }
+ return 0;
+}
|
