#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; }