summaryrefslogtreecommitdiff
path: root/src/02/04/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/02/04/main.c')
-rw-r--r--src/02/04/main.c28
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;
+}