diff --git a/Commun.c b/Commun.c index 572191f..d686569 100644 --- a/Commun.c +++ b/Commun.c @@ -1168,7 +1168,7 @@ Choix ** insererChoix(Choix *tChoix[], int *nombreChoix) /* Fonction permettant Choix ** supprimerChoix(Choix *tChoix[], int *nombreChoix) /* Fonction permettant de supprimer un choix d'un tableau de choix */ { - Choix **aux; /* Déclaration d'une variable aux prenant la valeur du tableau */ + Choix **aux, *temp; /* Déclaration d'une variable aux prenant la valeur du tableau */ int i, pos, trouve; char ville[31], dep[31], saisie; printf("Dans quelle ville se trouve la formation que vous souhaitez retirer de vos choix ?\nSaisie : "); /* Demande au candidat dans quelle ville supprimer le choix */ @@ -1190,6 +1190,7 @@ Choix ** supprimerChoix(Choix *tChoix[], int *nombreChoix) /* Fonction permettan { return tChoix; } + temp = tChoix[pos]; for(i = pos; i < *nombreChoix - 1; i++) /* Décalage à gauche des éléments du tableau à partir du dernier jusqu'au choix à supprimer */ { tChoix[i] = tChoix[i + 1]; @@ -1199,8 +1200,10 @@ Choix ** supprimerChoix(Choix *tChoix[], int *nombreChoix) /* Fonction permettan if(aux == NULL) { printf("Problème avec la réallocation lors de la suppression\n"); + free(temp); return tChoix; } + free(temp); return aux; } @@ -1496,6 +1499,116 @@ int rechercherCandidat(Candidat *tCand[], int tMax, int numeroC, int *trouve) /* return inf; } +/**************************************** File d'attente ****************************************************/ +/************************************************************************************************************/ +/************************************************************************************************************/ + +FileCand filenouv(void) +{ + FileCand f; + f.t = NULL; + f.q = NULL; + return f; +} + +FileCand adjq(FileCand f, Candidat *c) +{ + MaillonCandidat *m; + m = (MaillonCandidat *)malloc(sizeof(MaillonCandidat)); + if(m == NULL) + { + printf("Erreur de malloc pour la file d'attente\n"); + exit(1); + } + m->c = c; + m->suiv = NULL; + if(vide(f)) + { + f.t = m; + f.q = m; + return f; + } + f.q->suiv = m; + f.q = m; + return f; +} + +FileCand supt(FileCand f) +{ + MaillonCandidat *aux; + if(vide(f)) + { + printf("Opération interdite\n"); + exit(1); + } + if(f.t == f.q) + { + free(f.t); + return filenouv(); + } + aux = f.t; + f.t = f.t->suiv; + free(aux); + return f; +} + +Candidat * tete(FileCand f) +{ + if(vide(f)) + { + printf("File d'attente vide\n"); + exit(1); + } + return f.t->c; +} + +int longueur(FileCand f) +{ + int i = 0; + while(f.t != NULL) + { + f.t = f.t->suiv; + i++; + } + return i; +} + +int positionFileAttente(FileCand f, int numeroC) +{ + int i = 0; + while(f.t != NULL) + { + if(numeroC == f.t->c->numeroC) + { + return i; + } + f.t = f.t->suiv; + i++; + } + return i; +} + +bool vide(FileCand f) +{ + if(f.t == NULL && f.q == NULL) + return true; + return false; +} + +void afficher(FileCand f) +{ + printf("|----------------------------------------------------------------------------|\n"); + printf("| Liste d'attente |\n"); + printf("|----------------------------------------------------------------------------|\n"); + while(f.t != NULL) + { + printf("| %-4d | %-32s | %-32s |\n",f.t->c->numeroC, f.t->c->nom, f.t->c->prenom); + printf("|----------------------------------------------------------------------------|\n"); + f.t = f.t->suiv; + } + printf("\n"); +} + /********************************** Fonction globale et menus ***********************************************/ /************************************************************************************************************/ diff --git a/Commun.h b/Commun.h index 10478c9..f6b960a 100644 --- a/Commun.h +++ b/Commun.h @@ -109,6 +109,19 @@ typedef struct } Candidat; +typedef struct maillonCand +{ + Candidat *c; + struct maillonCand *suiv; +} MaillonCandidat; + +typedef struct +{ + MaillonCandidat *t; + MaillonCandidat *q; +} FileCand; + + /* Fonctions de Chargement et sauvegarde*/ Candidat ** chargementCandidats(int *tMax); @@ -150,6 +163,15 @@ void miseAJourChoixCand(Choix *tChoix[], int nombreChoix); void miseAJourChoixResp(Choix *tChoix[], int pos); Candidat ** creerCandidat(Candidat *tCand[], int *tMax); +/* Fonctions de file d'attente */ + +FileCand filenouv(void); +FileCand adjq(FileCand f, Candidat *c); +FileCand supt(FileCand f); +Candidat * tete(FileCand f); +int longueur(FileCand f); +int positionFileAttente(FileCand f, int numeroC); + /* Fonctions globale, menus*/ -void globale2(void); -void menuCandidat2(Candidat *tCand[], int tMax); \ No newline at end of file +void globale(void); +void menuCandidat(Candidat *tCand[], int tMax); \ No newline at end of file diff --git a/J2sae.c b/J2sae.c index 7bf1543..97a6b00 100755 --- a/J2sae.c +++ b/J2sae.c @@ -315,7 +315,7 @@ Choix ** insererChoix(Choix *tChoix[], int *nombreChoix) /* Fonction permettant Choix ** supprimerChoix(Choix *tChoix[], int *nombreChoix) /* Fonction permettant de supprimer un choix d'un tableau de choix */ { - Choix **aux; /* Déclaration d'une variable aux prenant la valeur du tableau */ + Choix **aux, *temp; /* Déclaration d'une variable aux prenant la valeur du tableau */ int i, pos, trouve; char ville[31], dep[31], saisie; printf("Dans quelle ville se trouve la formation que vous souhaitez retirer de vos choix ?\nSaisie : "); /* Demande au candidat dans quelle ville supprimer le choix */ @@ -337,6 +337,7 @@ Choix ** supprimerChoix(Choix *tChoix[], int *nombreChoix) /* Fonction permettan { return tChoix; } + temp = tChoix[pos]; for(i = pos; i < *nombreChoix - 1; i++) /* Décalage à gauche des éléments du tableau à partir du dernier jusqu'au choix à supprimer */ { tChoix[i] = tChoix[i + 1]; @@ -346,8 +347,10 @@ Choix ** supprimerChoix(Choix *tChoix[], int *nombreChoix) /* Fonction permettan if(aux == NULL) { printf("Problème avec la réallocation lors de la suppression\n"); + free(temp); return tChoix; } + free(temp); return aux; } @@ -643,6 +646,116 @@ int rechercherCandidat(Candidat *tCand[], int tMax, int numeroC, int *trouve) /* return inf; } +/**************************************** File d'attente ****************************************************/ +/************************************************************************************************************/ +/************************************************************************************************************/ + +FileCand filenouv(void) +{ + FileCand f; + f.t = NULL; + f.q = NULL; + return f; +} + +FileCand adjq(FileCand f, Candidat *c) +{ + MaillonCandidat *m; + m = (MaillonCandidat *)malloc(sizeof(MaillonCandidat)); + if(m == NULL) + { + printf("Erreur de malloc pour la file d'attente\n"); + exit(1); + } + m->c = c; + m->suiv = NULL; + if(vide(f)) + { + f.t = m; + f.q = m; + return f; + } + f.q->suiv = m; + f.q = m; + return f; +} + +FileCand supt(FileCand f) +{ + MaillonCandidat *aux; + if(vide(f)) + { + printf("Opération interdite\n"); + exit(1); + } + if(f.t == f.q) + { + free(f.t); + return filenouv(); + } + aux = f.t; + f.t = f.t->suiv; + free(aux); + return f; +} + +Candidat * tete(FileCand f) +{ + if(vide(f)) + { + printf("File d'attente vide\n"); + exit(1); + } + return f.t->c; +} + +int longueur(FileCand f) +{ + int i = 0; + while(f.t != NULL) + { + f.t = f.t->suiv; + i++; + } + return i; +} + +int positionFileAttente(FileCand f, int numeroC) +{ + int i = 0; + while(f.t != NULL) + { + if(numeroC == f.t->c->numeroC) + { + return i; + } + f.t = f.t->suiv; + i++; + } + return i; +} + +bool vide(FileCand f) +{ + if(f.t == NULL && f.q == NULL) + return true; + return false; +} + +void afficher(FileCand f) +{ + printf("|----------------------------------------------------------------------------|\n"); + printf("| Liste d'attente |\n"); + printf("|----------------------------------------------------------------------------|\n"); + while(f.t != NULL) + { + printf("| %-4d | %-32s | %-32s |\n",f.t->c->numeroC, f.t->c->nom, f.t->c->prenom); + printf("|----------------------------------------------------------------------------|\n"); + f.t = f.t->suiv; + } + printf("\n"); +} + /********************************** Fonction globale et menus ***********************************************/ /************************************************************************************************************/ diff --git a/J2sae.h b/J2sae.h index e77581e..bfbb98a 100755 --- a/J2sae.h +++ b/J2sae.h @@ -43,6 +43,19 @@ typedef struct } Candidat; +typedef struct maillonCand +{ + Candidat *c; + struct maillonCand *suiv; +} MaillonCandidat; + +typedef struct +{ + MaillonCandidat *t; + MaillonCandidat *q; +} FileCand; + + /* Fonctions de Chargement et sauvegarde*/ Candidat ** chargementCandidats(int *tMax); @@ -84,6 +97,15 @@ void miseAJourChoixCand(Choix *tChoix[], int nombreChoix); void miseAJourChoixResp(Choix *tChoix[], int pos); Candidat ** creerCandidat(Candidat *tCand[], int *tMax); +/* Fonctions de file d'attente */ + +FileCand filenouv(void); +FileCand adjq(FileCand f, Candidat *c); +FileCand supt(FileCand f); +Candidat * tete(FileCand f); +int longueur(FileCand f); +int positionFileAttente(FileCand f, int numeroC); + /* Fonctions globale, menus*/ void globale(void); void menuCandidat(Candidat *tCand[], int tMax);