16/12 lalalalalala

master
Louis LABORIE 2 years ago
parent cd6ad71cd1
commit 31f3989a50

260
SAEl.c

@ -1,127 +1,201 @@
#include "SAEl.h" #include "SAEl.h"
ListeDept creerListeDept(void)
ListeDept creerListeDept(void) { {
return NULL; return NULL;
} }
ListeDept ajouterEnTete(ListeDept l, char* dept, char* nom, int nbP) VilleIUT **chargementVille(char *nomFich, int tphys, int *tailleL)
{ {
MaillonDept *nouv; int i = 0, nbDept;
nouv = (MaillonDept *)malloc(sizeof(MaillonDept)); FILE *flot;
if (nouv == NULL) VilleIUT **tabV;
tabV = (VilleIUT **)malloc(sizeof(VilleIUT*) * tphys);
if (tabV == NULL)
{ {
printf("Erreur malloc !\n"); printf("Erreur malloc tab!\n");
exit(1); exit(1);
} }
nouv->departement = dept; flot = fopen(nomFich, "r");
nouv->nbPlaces = nbP; if (flot == NULL)
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"); printf("Problème ouverture du fichier !\n");
exit(1); exit(1);
} }
while (i != (pos - 1)) *tailleL = 0;
tabV[*tailleL] = (VilleIUT *)malloc(sizeof(VilleIUT));
if (tabV[*tailleL] == NULL)
{ {
l = l->suiv; printf("Erreur malloc ville!\n");
i += 1; fclose(flot);
exit(1);
} }
nouv->suiv = l->suiv; *(tabV[*tailleL]) = lireVille(flot);
l->suiv = nouv; while (!feof(flot))
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); fscanf(flot, "%d", &nbDept);
else printf("%d => ", l->x); printf("Nombre de dep : %d\n",nbDept);
l = l->suiv; while (i < nbDept)
{
tabV[*tailleL]->idDept = creerListeDept();
tabV[*tailleL]->idDept = traiterDept(tabV[*tailleL]->idDept, flot);
i += 1;
} }
} i = 0;
*tailleL += 1;
ListeDept inserer(ListeDept l, int x) { // récursif tabV[*tailleL] = (VilleIUT *)malloc(sizeof(VilleIUT));
if (l == NULL) return ajouterEnTête(l,x); if (tabV[*tailleL] == NULL)
if (x < l->v) return ajouterEnTête(l,x); {
if (x == l->v) return l; printf("Erreur malloc ville!\n");
l->suiv = inserer(l->suiv,x); fclose(flot);
return l;
}
ListeDept supprimerEnTête(ListeDept l) {
MaillonDept* aux;
if (l == NULL) {
printf("suppression interdite\n");
exit(1); exit(1);
} }
if (l->suiv == NULL) return NULL; *(tabV[*tailleL]) = lireVille(flot);
aux = l; }
l = l->suiv; if (tailleL == 0)
free(aux); printf("Fichier vide !\n");
return l; fclose(flot);
return tabV;
} }
VilleIUT lireVille(FILE *flot)
ListeDept supprimer(ListeDept l, int x) { {
if (l == NULL) return l; VilleIUT v;
if (x < l->v) return l; // si VRAI x ne peut pas se trouver dans la ListeDept fgets(v.ville, 30, flot);
if (l->v == x) return supprimerEnTête(l); v.ville[strlen(v.ville) - 1] = '\0';
l->suiv = supprimer(l->suiv,x); return v;
return l;
} }
ListeDept traiterDept(ListeDept l, FILE *flot)
void affichageListeDeptR(ListeDept l) { {
if (l->suiv == NULL) printf("%d\n",l->v); char nom[30], dept[30];
printf("%d =>",l->v); int nbPlaces;
affichageListeDeptR(l->suiv); fgets(dept, 30, flot);
dept[strlen(dept) - 1] = '\0';
fscanf(flot, "%d", &nbPlaces);
fgets(nom, 30, flot);
nom[strlen(nom) - 1] = '\0';
l = inserer(l, dept, nom, nbPlaces);
return l;
} }
int tete(ListeDept l) { ListeDept ajouterEnTete(ListeDept l, char *dept, char *nom, int nbP)
if (l == NULL) { {
printf("opération interdite\n"); MaillonDept *nouv;
nouv = (MaillonDept *)malloc(sizeof(MaillonDept));
if (nouv == NULL)
{
printf("Erreur malloc !\n");
exit(1); exit(1);
} }
return l->v; strcpy(nouv->departement,dept);
} nouv->nbPlaces = nbP;
strcpy(nouv->nom,nom);
nouv->suiv = l;
bool vide(ListeDept l) { return nouv;
if (l == NULL) return true; // 1
return false; // 0
} }
int longueur(ListeDept l) { void affichageListeDept(ListeDept l) // itératif
int cpt = 0; {
while (l != NULL) { printf("DEPARTEMENT NOMBRE DE PLACES CHEF\n");
cpt + 1; while (l != NULL)
{
printf("%s\t%d\t%s\n", l->departement, l->nbPlaces, l->nom);
l = l->suiv; l = l->suiv;
} }
return cpt;
} }
bool recherche(ListeDept l, int x) { ListeDept inserer(ListeDept l, char *dept, char *nom, int nbP)
if (l == NULL) return false; { // récursif
if (x < l->v) return false; if (l == NULL)
if (x == l->v) return true; return ajouterEnTete(l, dept, nom, nbP);
return recherche(l->suiv, x); if ((strcmp(dept,l->departement)) < 0)
} return ajouterEnTete(l, dept, nom, nbP);
if ((strcmp(dept,l->departement)) == 0)
ListeDept ajouterEnQueue(ListeDept l, int x) { return l;
if (l == NULL) return ajouterEnTête(l,x); l->suiv = inserer(l->suiv, dept, nom, nbP);
l->suiv = ajouterEnQueue(l->suiv,x);
return l; 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;
// }

@ -22,4 +22,13 @@ ListeDept creerListeDept(void);
ListeDept ajouterEnTete(ListeDept l, char* dept, char* nom, int nbP); ListeDept ajouterEnTete(ListeDept l, char* dept, char* nom, int nbP);
void ajouterPos(ListeDept l, char* dept, char* nom, int nbP, int pos); ListeDept inserer(ListeDept l, char *dept, char *nom, int nbP);
void affichageListeDept(ListeDept l);
VilleIUT lireVille(FILE *flot);
ListeDept traiterDept(ListeDept l, FILE *flot);
VilleIUT** chargementVille(char* nomFich, int tphys, int* tailleL);

@ -0,0 +1,16 @@
Clermont-Ferrand
2
Informatique
130
Bouhours Cédric
Réseaux
5
Unmec Sympa
Lyon
2
Jeux-videos
24
Kojima Hideo
GEA
8
Macron Emmanuel
Loading…
Cancel
Save