From ffef124dc697fcf95b9a62b48a668799932cbbad Mon Sep 17 00:00:00 2001 From: Louis LABORIE Date: Thu, 15 Dec 2022 09:52:39 +0100 Subject: [PATCH] =?UTF-8?q?euh=20oui=20je=20fais=20un=20commit=20l=C3=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SAEl.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++- SAEl.h | 7 ++- testSAE.c | 2 +- 3 files changed, 131 insertions(+), 6 deletions(-) diff --git a/SAEl.c b/SAEl.c index 9ff7db0..e276248 100644 --- a/SAEl.c +++ b/SAEl.c @@ -1 +1,127 @@ -#include "SAE.h" \ No newline at end of file +#include "SAEl.h" + + +ListeDept creerListeDept(void) { + return NULL; +} + +ListeDept ajouterEnTete(ListeDept l, char* dept, char* nom, int nbP) +{ + MaillonDept *nouv; + nouv = (MaillonDept *)malloc(sizeof(MaillonDept)); + if (nouv == NULL) + { + printf("Erreur malloc !\n"); + exit(1); + } + nouv->departement = dept; + nouv->nbPlaces = nbP; + nouv->nom = nom; + nouv->suiv = l; + return nouv; +} + +void ajouterPos(ListeDept l, char* dept, char* nom, int nbP, int pos) +{ + MaillonDept *nouv; + int i = 0; + nouv = (MaillonDept *)malloc(sizeof(MaillonDept)); + if (nouv == NULL) + { + printf("Erreur malloc !\n"); + exit(1); + } + while (i != (pos - 1)) + { + l = l->suiv; + i += 1; + } + nouv->suiv = l->suiv; + l->suiv = nouv; + nouv->departement = dept; + nouv->nbPlaces = nbP; + nouv->nom = nom; +} + +void affichageListeDept(ListeDept l) // itératif +{ + while (l != NULL) + { + if (l->suiv == NULL) printf("%d\n",l->x); + else printf("%d => ", l->x); + l = l->suiv; + } +} + +ListeDept inserer(ListeDept l, int x) { // récursif + if (l == NULL) return ajouterEnTête(l,x); + if (x < l->v) return ajouterEnTête(l,x); + if (x == l->v) return l; + l->suiv = inserer(l->suiv,x); + return l; +} + +ListeDept supprimerEnTête(ListeDept l) { + MaillonDept* aux; + if (l == NULL) { + printf("suppression interdite\n"); + exit(1); + } + if (l->suiv == NULL) return NULL; + aux = l; + l = l->suiv; + free(aux); + return l; +} + + +ListeDept supprimer(ListeDept l, int x) { + if (l == NULL) return l; + if (x < l->v) return l; // si VRAI x ne peut pas se trouver dans la ListeDept + if (l->v == x) return supprimerEnTête(l); + l->suiv = supprimer(l->suiv,x); + return l; +} + + +void affichageListeDeptR(ListeDept l) { + if (l->suiv == NULL) printf("%d\n",l->v); + printf("%d =>",l->v); + affichageListeDeptR(l->suiv); +} + +int tete(ListeDept l) { + if (l == NULL) { + printf("opération interdite\n"); + exit(1); + } + return l->v; +} + + +bool vide(ListeDept l) { + if (l == NULL) return true; // 1 + return false; // 0 +} + +int longueur(ListeDept l) { + int cpt = 0; + while (l != NULL) { + cpt + 1; + l = l->suiv; + } + return cpt; +} + +bool recherche(ListeDept l, int x) { + if (l == NULL) return false; + if (x < l->v) return false; + if (x == l->v) return true; + return recherche(l->suiv, x); +} + +ListeDept ajouterEnQueue(ListeDept l, int x) { + if (l == NULL) return ajouterEnTête(l,x); + l->suiv = ajouterEnQueue(l->suiv,x); + return l; +} \ No newline at end of file diff --git a/SAEl.h b/SAEl.h index 8eb4ecd..03e0bc1 100644 --- a/SAEl.h +++ b/SAEl.h @@ -18,9 +18,8 @@ typedef struct { ListeDept idDept; }VilleIUT; +ListeDept creerListeDept(void); +ListeDept ajouterEnTete(ListeDept l, char* dept, char* nom, int nbP); - - - - +void ajouterPos(ListeDept l, char* dept, char* nom, int nbP, int pos); \ No newline at end of file diff --git a/testSAE.c b/testSAE.c index 9ff7db0..ccc908b 100644 --- a/testSAE.c +++ b/testSAE.c @@ -1 +1 @@ -#include "SAE.h" \ No newline at end of file +#include "SAEl.h" \ No newline at end of file