From bd9dfa66abfb97e3c85ec25060ca7e8985d15938 Mon Sep 17 00:00:00 2001 From: Siwa12100 Date: Fri, 13 Jan 2023 20:48:12 +0100 Subject: [PATCH 1/2] recuperation de la partie 4 ( Jean ) --- source/partie4.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++ source/test.c | 6 +-- 2 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 source/partie4.c diff --git a/source/partie4.c b/source/partie4.c new file mode 100644 index 0000000..f440398 --- /dev/null +++ b/source/partie4.c @@ -0,0 +1,103 @@ +#include "../header/sae.h" + +// ============================================================================== +// 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 ); + + 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; + } +} +/** + * @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; + + while ( l != NULL ) + { + nvL = insertionCroissanteCand( nvL, l ); + l = l -> suiv; + } + + 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) + { + 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; +} + +/** + * @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 )); + if ( m == NULL ) + { + printf("\n -> Erreur allocation memoire...\n"); + exit(1); + } + + m -> candidat = l -> candidat; + m -> suiv = nvL; + nvL = m; + free( l ); + + return nvL; +} diff --git a/source/test.c b/source/test.c index bdaf692..00838f2 100644 --- a/source/test.c +++ b/source/test.c @@ -68,11 +68,7 @@ void guillaume(void) tCandid[0] -> lchoix = supprimerCandidature(tCandid[0]->lchoix, tCandid[0]->nbChoix); tCandid[0]->nbChoix-=1; - - //tCandid[0] -> lchoix = supprmRecru ( tCandid[0] -> lchoix, 1); - - printf(" ( temporaire( 4 )... --> %s \n\n", tCandid[0] -> lchoix -> ville); - + afficherUnCandidat(*tCandid[0]); } From b092b29fcec9a95286488850700787d4cc787a2c Mon Sep 17 00:00:00 2001 From: DahmaneYanis Date: Fri, 13 Jan 2023 22:17:59 +0100 Subject: [PATCH 2/2] Test programme fonctionnel --- source/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/main.c b/source/main.c index 184f5ca..44200a6 100644 --- a/source/main.c +++ b/source/main.c @@ -8,9 +8,9 @@ int main(void) // #ifdef _WIN32 // color // #endif - guillaume(); + //guillaume(); //testCharge(); - //Globale(); + Globale(); //testJean(); return 0;