From b3a48e027c202a741746d45ce3ec1c0ac477ffc2 Mon Sep 17 00:00:00 2001 From: Siwa12100 Date: Thu, 12 Jan 2023 18:00:03 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=20Ajout=20de=20la=20partie=204=20(=20Jean?= =?UTF-8?q?=20)=20avec=20affichage=20des=20listes=20et=20trie=20des=20list?= =?UTF-8?q?es=20par=20ordre=20alphab=C3=A9tique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- header/sae.h | 6 ++++ source/sae.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/header/sae.h b/header/sae.h index 20cf190..e8d852c 100644 --- a/header/sae.h +++ b/header/sae.h @@ -126,6 +126,12 @@ void menuAdmin(VilleIut **villeIut, int nbVilles); void afficherCandidat(Candidat candidat); void afficherCandidats(Candidat *candidats, int nbCandidats); +ListeDeptV2 configurationDeptV2( ListeDept ldept ); + +void affichageListesDept( ListeCandidats lcand, char * type, char * nomDept ); +ListeCandidats trierListeCandidats( ListeCandidats l ); +ListeCandidats insertionCroissanteCand( ListeCandidats nvL, ListeCandidats l ); +ListeCandidats insertionTeteCand( ListeCandidats nvL, ListeCandidats l ); // listeDeparements.c ListeDept ajouterEnTete(ListeDept ldept, char nomDept[], char resp[], int nbP); diff --git a/source/sae.c b/source/sae.c index 4f89073..1a4a469 100644 --- a/source/sae.c +++ b/source/sae.c @@ -571,7 +571,8 @@ ListeDeptV2 configurationDeptV2( ListeDept ldept ) exit(1); } - MaillonDeptV2 * mV2 = ( MaillonDeptV2 ) malloc ( sizeof( MaillonDeptV2 )); + MaillonDeptV2 * mV2 = ( MaillonDeptV2 * ) malloc ( sizeof( MaillonDeptV2 )); + if ( mV2 == NULL) { printf("\n --> Erreur d'allocation memoire...\n"); exit(1); @@ -599,4 +600,83 @@ ListeDeptV2 configurationDeptV2( ListeDept ldept ) } return lDeptV2; +} + + + +// ============================================================================== +// Partie 4 +// ============================================================================== + +void affichageListesDept( ListeCandidats lcand, char * type, char * nomDept ) +{ + lcand = trierListeCandidats( lcand ); + + printf( " Liste des candidats %s du departement %10s \n -------------------------------------------------------\n\n", type, nomDept); + + while ( lcand != NULL) + { + printf(" | Nom : %10s | Prenom : %10s | Numero : %8s |\n", + lcand -> candidat.nom, lcand -> candidat.prenom, lcand -> candidat.numero); + + lcand = lcand -> suiv; + } +} + +ListeCandidats trierListeCandidats( ListeCandidats l ) +{ + ListeCandidats nvL; + + while ( l != NULL ) + { + nvL = insertionCroissanteCand( nvL, l ); + l = l -> suiv; + } + + return nvL; +} + +ListeCandidats insertionCroissanteCand( ListeCandidats nvL, ListeCandidats l ) +{ + if ( l == NULL) + { + nvL = insertionTeteCand( nvL, l ); + return nvL; + } + + if ( strcmp( l -> candidat.nom, nvL -> candidat.nom ) < 0 ) + { + nvL = insertionTeteCand( nvL, l ); + return nvL; + } + + if ( strcmp( l -> candidat.nom, nvL -> candidat.nom ) == 0 ) + { + if ( strcmp( l -> candidat.prenom, nvL -> candidat.prenom ) < 0 ) + { + nvL = insertionTeteCand( nvL, l ); + return nvL; + } + } + + nvL -> suiv = insertionCroissanteCand( nvL -> suiv, l ); + return nvL; +} + + +ListeCandidats insertionTeteCand( ListeCandidats nvL, ListeCandidats l ) +{ + MaillonCandidat * m = ( MaillonCandidat * ) malloc ( sizeof( MaillonCandidat )); + if ( m == NULL ) + { + printf("\n -> Erreur allocation memoire...\n"); + exit(1); + } + + m -> candidat = l -> candidat; + m -> suiv = nvL; + nvL = m; + free( l ); + + return nvL; } \ No newline at end of file From 7b909fedfbb296403ffe94c0ab73aca2ee0f0001 Mon Sep 17 00:00:00 2001 From: Siwa12100 Date: Thu, 12 Jan 2023 18:07:10 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=20Ajout=20de=20la=20partie=204=20(=20Jean?= =?UTF-8?q?=20)=20avec=20affichage=20des=20listes=20et=20trie=20des=20list?= =?UTF-8?q?es=20par=20ordre=20alphab=C3=A9tique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/sae.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/source/sae.c b/source/sae.c index 1a4a469..2882571 100644 --- a/source/sae.c +++ b/source/sae.c @@ -608,6 +608,13 @@ ListeDeptV2 configurationDeptV2( ListeDept ldept ) // Partie 4 // ============================================================================== +/** + * @brief Affiche une liste de candidats après l'avoir triée par ordre alphabétique + * + * @param lcand liste de candidats à trier et afficher + * @param type type de liste à afficher ( en attente ou admis ) + * @param nomDept nom du departement dont est issu la liste + */ void affichageListesDept( ListeCandidats lcand, char * type, char * nomDept ) { lcand = trierListeCandidats( lcand ); @@ -622,7 +629,13 @@ void affichageListesDept( ListeCandidats lcand, char * type, char * nomDept ) lcand = lcand -> suiv; } } - +/** + * @brief Trie par ordre alphabétique les candidats d'une liste + * + * @param l liste de candidats à trier. + * + * @return La liste triée + */ ListeCandidats trierListeCandidats( ListeCandidats l ) { ListeCandidats nvL; @@ -636,6 +649,13 @@ ListeCandidats trierListeCandidats( ListeCandidats l ) return nvL; } +/** + * @brief Permet d'insérer un nouveau Maillon de candidats dans la liste par ordre alphabétique + * @param l la liste dont est issu le maillon à insérer + * @param nvL la nouvelle liste où est inséré le maillon + * + * @return La nouvelle liste avec le maillon au bon endroit + */ ListeCandidats insertionCroissanteCand( ListeCandidats nvL, ListeCandidats l ) { if ( l == NULL) @@ -663,7 +683,12 @@ ListeCandidats insertionCroissanteCand( ListeCandidats nvL, ListeCandidats l ) return nvL; } - +/** + * @brief Insère en tête de la nouvelle liste un nouveau maillon + * @param l liste d'où est issu le nouveau maillon à intégrer + * @param nvL Liste où est insérer le nouveau Maillon + * @return La nouvelle liste avec le maillon au bon endroit + */ ListeCandidats insertionTeteCand( ListeCandidats nvL, ListeCandidats l ) { MaillonCandidat * m = ( MaillonCandidat * ) malloc ( sizeof( MaillonCandidat ));