From a6ca349c4001cfc95b91320b272d6002c359e6f4 Mon Sep 17 00:00:00 2001 From: Arkitu Date: Tue, 16 Dec 2025 15:58:30 +0100 Subject: [PATCH] tp7 exo1 --- tp7/exo1.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tp7/exo1.c diff --git a/tp7/exo1.c b/tp7/exo1.c new file mode 100644 index 0000000..433d0c6 --- /dev/null +++ b/tp7/exo1.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include + +struct t_r_i { + int taille; + int capacite; + int *donnees; +}; +typedef struct t_r_i itr; +itr creer_itr(int capacite) { + int c = 1; + while (capacite) { + c *= 2; + capacite /= 2; + } + itr t; + t.taille = 0; + t.capacite = c; + t.donnees = malloc(c * sizeof(int)); + return t; +} +int taille_itr(itr t) { return t.taille; } +int acces_itr(itr t, int i) { return t.donnees[i]; } +void modif_itr(itr t, int i, int x) { t.donnees[i] = x; } +void append_itr(itr *t, int x) { + if (t->taille + 1 <= t->capacite) { + t->donnees[t->taille] = x; + } else { + int c = t->capacite * 2; + int *t2 = malloc(c * sizeof(int)); + + for (int i = 0; i < t->taille; i += 1) { + t2[i] = t->donnees[i]; + } + t2[t->taille] = x; + free(t->donnees); + t->donnees = t2; + } +} +int pop_itr(itr *t) { + t->taille = t->taille - 1; + return t->donnees[t->taille]; +} +// let's goooooooooo maxime primeeeeeeeee