From d41b086229fe9336e6c17e90faa8793ebe770bed Mon Sep 17 00:00:00 2001
From: "dario.genga" <dario.genga@etu.hesge.ch>
Date: Tue, 3 May 2022 16:08:36 +0200
Subject: [PATCH] Add finished ex2

---
 ex2/ex2.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/ex2/ex2.c b/ex2/ex2.c
index 878e30c..a56feba 100644
--- a/ex2/ex2.c
+++ b/ex2/ex2.c
@@ -88,6 +88,24 @@ hm *hm_set(hm *hm, const char *const key, double value) {
     return hm;
 }
 
+void hm_print(const hm *const hm) {
+    for (int i = 0; i < hm->length; i++) {
+        printf("%d: ", i);
+        entry *e = hm->entries[i];
+        while (e != NULL && e->key != NULL) {
+            printf("(");
+            printf("%s, ", e->key);
+            printf("%0.1f)", e->value);
+
+            if (e->next != NULL && e->next->key != NULL) {
+                printf(", ");
+            }
+            e = e->next;
+        }
+
+        printf("\n");
+    }
+}
 
 int main() {
     int length = 10;
@@ -104,13 +122,15 @@ int main() {
     hm_set(hashmap, "bjkd", 1.9);
 
     // print
-
+    hm_print(hashmap);
 
     hm_set(hashmap, "ajkt", 0.1);
     hm_set(hashmap, "ajku", 9.1);
     hm_set(hashmap, "ajkx", 2.9);
 
     // print
+    printf("-------------------\n");
+    hm_print(hashmap);
 
     hm_destroy(&hashmap);
     return EXIT_SUCCESS;
-- 
GitLab