You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
2.6 KiB
120 lines
2.6 KiB
#include "SAE.h"
|
|
|
|
// ListeChoix
|
|
|
|
ListeChoix listenouvChoix(void)
|
|
{
|
|
ListeChoix lc;
|
|
lc = NULL;
|
|
return lc;
|
|
}
|
|
|
|
ListeChoix insererEnTeteChoix(ListeChoix lc, Choix choix)
|
|
{
|
|
MaillonChoix *p;
|
|
p = (MaillonChoix *)malloc(sizeof(MaillonChoix));
|
|
if (p == NULL)
|
|
{
|
|
printf("Opérations interdites !!!!\n");
|
|
exit(1);
|
|
}
|
|
p->choix = choix;
|
|
p->suiv = lc;
|
|
return p;
|
|
}
|
|
|
|
ListeChoix insererChoix(ListeChoix lc, Choix choix)
|
|
{
|
|
if (videChoix(lc))
|
|
return insererEnTeteChoix(lc, choix);
|
|
if (strcmp(choix.ville, lc->choix.ville) < 0)
|
|
return insererEnTeteChoix(lc, choix);
|
|
if (strcmp(choix.ville, lc->choix.ville) == 0)
|
|
{
|
|
if (strcmp(choix.departement, lc->choix.departement) != 0)
|
|
return insererEnTeteChoix(lc, choix);
|
|
lc->choix = choix;
|
|
}
|
|
lc->suiv = insererChoix(lc->suiv, choix);
|
|
return lc;
|
|
}
|
|
|
|
ListeChoix supprimerEnTeteChoix(ListeChoix lc)
|
|
{
|
|
MaillonChoix *aux;
|
|
if (videChoix(lc))
|
|
{
|
|
printf("Opérations interdites !!!!\n");
|
|
exit(1);
|
|
}
|
|
aux = lc;
|
|
lc = lc->suiv;
|
|
free(aux);
|
|
return lc;
|
|
}
|
|
|
|
ListeChoix supprimerChoix(ListeChoix lc, Choix choix)
|
|
{
|
|
if (videChoix(lc))
|
|
return lc;
|
|
if (strcmp(choix.ville, lc->choix.ville) < 0)
|
|
return lc;
|
|
if (strcmp(choix.ville, lc->choix.ville) == 0)
|
|
if (strcmp(choix.departement, lc->choix.departement) == 0)
|
|
return supprimerEnTeteChoix(lc);
|
|
lc->suiv = supprimerChoix(lc->suiv, lc->choix);
|
|
return lc;
|
|
}
|
|
|
|
bool rechercherChoix(ListeChoix lc, Choix choix)
|
|
{
|
|
if (videChoix(lc))
|
|
return false;
|
|
if (strcmp(choix.ville, lc->choix.ville) < 0)
|
|
return false;
|
|
if (strcmp(choix.ville, lc->choix.ville) == 0)
|
|
if (strcmp(choix.departement, lc->choix.departement) == 0)
|
|
return true;
|
|
return rechercherChoix(lc->suiv, lc->choix);
|
|
}
|
|
|
|
Choix TeteChoix(ListeChoix lc)
|
|
{
|
|
if (videChoix(lc))
|
|
{
|
|
printf("Opérations interdites !!!!\n");
|
|
exit(1);
|
|
}
|
|
return lc->choix; /* Retourne un choix (ville) */
|
|
}
|
|
|
|
bool videChoix(ListeChoix lc)
|
|
{
|
|
return lc == NULL;
|
|
}
|
|
|
|
void afficherChoix(ListeChoix lc)
|
|
{
|
|
while (!videChoix(lc))
|
|
{
|
|
afficherCandidatsChoix(TeteChoix(lc));
|
|
lc = lc->suiv;
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
int longueurChoix(ListeChoix lc)
|
|
{
|
|
int cpt = 0;
|
|
while (!videChoix(lc))
|
|
{
|
|
cpt++;
|
|
lc = lc->suiv;
|
|
}
|
|
return cpt;
|
|
}
|
|
|
|
void afficherCandidatsChoix(Choix choix)
|
|
{
|
|
printf("Ville : %s\nDépartement : %s\nAdmission : %d\nCandidat : %d\n", choix.ville, choix.departement, choix.decisionAdmission, choix.decisionCandidat);
|
|
} |