aboutsummaryrefslogtreecommitdiff
path: root/semestre 3/structures des données/td/td3/exo4.c
diff options
context:
space:
mode:
Diffstat (limited to 'semestre 3/structures des données/td/td3/exo4.c')
-rw-r--r--semestre 3/structures des données/td/td3/exo4.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/semestre 3/structures des données/td/td3/exo4.c b/semestre 3/structures des données/td/td3/exo4.c
new file mode 100644
index 0000000..02134c8
--- /dev/null
+++ b/semestre 3/structures des données/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);
+}
+