diff options
| author | Tyge Løvset <[email protected]> | 2022-06-01 16:28:07 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-06-01 16:28:07 +0200 |
| commit | de629774cb912aa3d563f24d99258142713c3fcd (patch) | |
| tree | c37e2851d6cb049bc0863a59b6ecf5945fb88619 /examples/unordered_map.c | |
| parent | 7fb43a24a17da787dd809114ca26c1231b058493 (diff) | |
| download | STC-modified-de629774cb912aa3d563f24d99258142713c3fcd.tar.gz STC-modified-de629774cb912aa3d563f24d99258142713c3fcd.zip | |
Converted all files with DOS line endings to LINUX.
Diffstat (limited to 'examples/unordered_map.c')
| -rw-r--r-- | examples/unordered_map.c | 128 |
1 files changed, 64 insertions, 64 deletions
diff --git a/examples/unordered_map.c b/examples/unordered_map.c index 7af6fa0a..c4a05c76 100644 --- a/examples/unordered_map.c +++ b/examples/unordered_map.c @@ -1,64 +1,64 @@ -// https://iq.opengenus.org/containers-cpp-stl/
-
-#define i_key int
-#define i_val int
-#include <stc/csmap.h>
-#include <stdio.h>
-
-int main()
-{
-
- // empty map containers
- c_auto (csmap_int, gquiz1, gquiz2)
- {
- // insert elements in random order
- csmap_int_insert(&gquiz1, 2, 30);
- csmap_int_insert(&gquiz1, 4, 20);
- csmap_int_insert(&gquiz1, 7, 10);
- csmap_int_insert(&gquiz1, 5, 50);
- csmap_int_insert(&gquiz1, 3, 60);
- csmap_int_insert(&gquiz1, 1, 40);
- csmap_int_insert(&gquiz1, 6, 50);
-
- // printing map gquiz1
- printf("\nThe map gquiz1 is :\n\tKEY\tELEMENT\n");
- c_foreach (itr, csmap_int, gquiz1)
- printf("\t%d\t%d\n", itr.ref->first, itr.ref->second);
- printf("\n");
-
- // assigning the elements from gquiz1 to gquiz2
- c_foreach (i, csmap_int, gquiz1)
- csmap_int_insert(&gquiz2, i.ref->first, i.ref->second);
-
- // print all elements of the map gquiz2
- printf("\nThe map gquiz2 is :\n\tKEY\tELEMENT\n");
- c_foreach (itr, csmap_int, gquiz2)
- printf("\t%d\t%d\n", itr.ref->first, itr.ref->second);
- printf("\n");
-
- // remove all elements up to element with key=3 in gquiz2
- printf("\ngquiz2 after removal of elements less than key=3 :\n");
- printf("\tKEY\tELEMENT\n");
- csmap_int_erase_range(&gquiz2, csmap_int_begin(&gquiz2),
- csmap_int_find(&gquiz2, 3));
- c_foreach (itr, csmap_int, gquiz2)
- printf("\t%d\t%d\n", itr.ref->first, itr.ref->second);
- printf("\n");
-
- // remove all elements with key = 4
- int num = csmap_int_erase(&gquiz2, 4);
- printf("\ngquiz2.erase(4) : %d removed\n", num);
- printf("\tKEY\tELEMENT\n");
- c_foreach (itr, csmap_int, gquiz2)
- printf("\t%d\t%d\n", itr.ref->first, itr.ref->second);
- printf("\n");
-
- // lower bound and upper bound for map gquiz1 key = 5
- printf("gquiz1.lower_bound(5) : ");
- printf("\tKEY = %d\t", csmap_int_lower_bound(&gquiz1, 5).ref->first);
- printf("\tELEMENT = %d\n", csmap_int_lower_bound(&gquiz1, 5).ref->second);
- printf("gquiz1.upper_bound(5) : ");
- printf("\tKEY = %d\t", csmap_int_lower_bound(&gquiz1, 5+1).ref->first);
- printf("\tELEMENT = %d\n", csmap_int_lower_bound(&gquiz1, 5+1).ref->second);
- }
-}
+// https://iq.opengenus.org/containers-cpp-stl/ + +#define i_key int +#define i_val int +#include <stc/csmap.h> +#include <stdio.h> + +int main() +{ + + // empty map containers + c_auto (csmap_int, gquiz1, gquiz2) + { + // insert elements in random order + csmap_int_insert(&gquiz1, 2, 30); + csmap_int_insert(&gquiz1, 4, 20); + csmap_int_insert(&gquiz1, 7, 10); + csmap_int_insert(&gquiz1, 5, 50); + csmap_int_insert(&gquiz1, 3, 60); + csmap_int_insert(&gquiz1, 1, 40); + csmap_int_insert(&gquiz1, 6, 50); + + // printing map gquiz1 + printf("\nThe map gquiz1 is :\n\tKEY\tELEMENT\n"); + c_foreach (itr, csmap_int, gquiz1) + printf("\t%d\t%d\n", itr.ref->first, itr.ref->second); + printf("\n"); + + // assigning the elements from gquiz1 to gquiz2 + c_foreach (i, csmap_int, gquiz1) + csmap_int_insert(&gquiz2, i.ref->first, i.ref->second); + + // print all elements of the map gquiz2 + printf("\nThe map gquiz2 is :\n\tKEY\tELEMENT\n"); + c_foreach (itr, csmap_int, gquiz2) + printf("\t%d\t%d\n", itr.ref->first, itr.ref->second); + printf("\n"); + + // remove all elements up to element with key=3 in gquiz2 + printf("\ngquiz2 after removal of elements less than key=3 :\n"); + printf("\tKEY\tELEMENT\n"); + csmap_int_erase_range(&gquiz2, csmap_int_begin(&gquiz2), + csmap_int_find(&gquiz2, 3)); + c_foreach (itr, csmap_int, gquiz2) + printf("\t%d\t%d\n", itr.ref->first, itr.ref->second); + printf("\n"); + + // remove all elements with key = 4 + int num = csmap_int_erase(&gquiz2, 4); + printf("\ngquiz2.erase(4) : %d removed\n", num); + printf("\tKEY\tELEMENT\n"); + c_foreach (itr, csmap_int, gquiz2) + printf("\t%d\t%d\n", itr.ref->first, itr.ref->second); + printf("\n"); + + // lower bound and upper bound for map gquiz1 key = 5 + printf("gquiz1.lower_bound(5) : "); + printf("\tKEY = %d\t", csmap_int_lower_bound(&gquiz1, 5).ref->first); + printf("\tELEMENT = %d\n", csmap_int_lower_bound(&gquiz1, 5).ref->second); + printf("gquiz1.upper_bound(5) : "); + printf("\tKEY = %d\t", csmap_int_lower_bound(&gquiz1, 5+1).ref->first); + printf("\tELEMENT = %d\n", csmap_int_lower_bound(&gquiz1, 5+1).ref->second); + } +} |
