From 85fbaa4d9381e435be129aa7bc4ea6a472acb2b2 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Sun, 5 Oct 2025 16:28:33 +0200 Subject: Cours du 29 au 3 octobre --- .../structures des donn\303\251es/td/td3/exo4.c" | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "semestre 3/structures des donn\303\251es/td/td3/exo4.c" (limited to 'semestre 3/structures des données/td/td3/exo4.c') diff --git "a/semestre 3/structures des donn\303\251es/td/td3/exo4.c" "b/semestre 3/structures des donn\303\251es/td/td3/exo4.c" new file mode 100644 index 0000000..02134c8 --- /dev/null +++ "b/semestre 3/structures des donn\303\251es/td/td3/exo4.c" @@ -0,0 +1,44 @@ +typedef struct cell{ + int val; + int key; + cell* next; +} Cell; + +typedef struct hashMap{ + int size; + cell** map; +} HashMap; + +void mapInsert(HashMap* map, int val){ + map->map[g(val)] = val; +} + +int mapLen(HashMap* map){ + int len = 0; + for (int i = 0; i < map->size; i++){ + Cell* v = map->map[i]; + while (v){ + len++; + v = v->next; + } + } + return len; +} + +void mapDel(HashMap* map, int val){ + Cell* f = map->map[g(val)]; + Cell* v = f; + Cell* b; + while (v && v->val != val){ + b = v; + v = v->next; + } + if (v->val != val) return; + if (!b){ + f = v->next; + } else { + b = v->next; + } + free(v); +} + -- cgit v1.2.3