diff options
| author | mo khan <mo.khan@gmail.com> | 2020-08-03 15:49:36 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-08-03 15:49:36 -0600 |
| commit | 8b6d6e4756008d412bd5daf3db44f3537deacd3f (patch) | |
| tree | dc06b9839087b36db120c4ddcd6abb1af7a25f99 /src/02/04/main.c | |
| parent | 3bf3ca9b3aede625fdc818e01ad0128db7cce9f6 (diff) | |
Create program to display hash table
Diffstat (limited to 'src/02/04/main.c')
| -rw-r--r-- | src/02/04/main.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/02/04/main.c b/src/02/04/main.c index 1044d74..0db6346 100644 --- a/src/02/04/main.c +++ b/src/02/04/main.c @@ -1,3 +1,29 @@ #include <stdio.h> +#include "hash.h" -int main(int argc, char *argv[]) { return 0; } +int main(int argc, char *argv[]) { + printf("=== COMP-272 - Assignment 02 - Question 04 ===\n"); + Hash *hash = hash_init(13); + int items[] = {1, 5, 21, 26, 39, 14, 15, 16, 17, 18, 19, 20, 111, 145, 146}; + int n = sizeof(items) / sizeof(int); + + printf("Insert items into hash\n"); + for (int i = 0; i < n; i++) { + int key = items[i]; + long value = key * 10; + printf("(%d:%d) ", key, value); + hash_set(hash, key, (void *)value); + } + + printf("\nInspect hash table\n"); + hash_inspect(hash); + + printf("Retrieve each item from the table\n"); + for (int i = 0; i < n; i++) { + int key = items[i]; + printf("(%d:%d) ", key, hash_get(hash, key)); + } + + printf("\nBye\n"); + return 0; +} |
