From 09fd004a6896abf543b13dd99109bbcd35f2d767 Mon Sep 17 00:00:00 2001 From: Pradheep Unnikrishnan <pradheep.unnikrishnan@etu.unistra.fr> Date: Fri, 22 Mar 2024 18:46:09 +0100 Subject: [PATCH] =?UTF-8?q?mise=20=C3=A0=20jour?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../code_modifie/reorganisation/alea.c | 6 ++ .../code_modifie/reorganisation/io.c | 6 +- .../code_modifie/reorganisation/remplir.c | 7 ++- .../code_modifie/reorganisation/remplir.h | 1 - .../code_modifie/reorganisation/src/alea.c | 13 ---- .../code_modifie/reorganisation/src/io.c | 15 ----- .../code_modifie/reorganisation/src/main.c | 61 ------------------- .../code_modifie/reorganisation/src/remplir.c | 15 ----- .../code_modifie/reorganisation/src/tri.c | 35 ----------- .../code_modifie/reorganisation/tableau.h | 2 +- .../code_modifie/reorganisation/tri.c | 23 +++++-- .../code_modifie/reorganisation/tri.h | 1 - 12 files changed, 35 insertions(+), 150 deletions(-) delete mode 100644 TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/alea.c delete mode 100644 TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/io.c delete mode 100755 TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/main.c delete mode 100644 TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/remplir.c delete mode 100644 TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/tri.c diff --git a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/alea.c b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/alea.c index e63d7b1..4a4ad6e 100644 --- a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/alea.c +++ b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/alea.c @@ -1,5 +1,11 @@ #include "alea.h" +/** + *@fn int alea(int m) + *@brief Génère une valeur aléatoire entre 0 et m + *@param m Limite supérieur pour la création d'un nombre aléatoire + *@return Un entier aléatoire entre 0 et m +*/ int alea(int m) { return rand() % (m + 1); diff --git a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/io.c b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/io.c index 63e00d3..2b9cd8b 100644 --- a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/io.c +++ b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/io.c @@ -1,11 +1,15 @@ #include "io.h" +/** + * @fn void affiche() + * @brief Affiche les élements du tableau t +*/ void affiche() { int i; for (i = 0; i < t.taille; i++) { - printf("%d\t", t.valeurs[i]); + printf("%d\t", t.valeur[i]); } printf("\n"); } \ No newline at end of file diff --git a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/remplir.c b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/remplir.c index c7ac6f3..2f740b8 100644 --- a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/remplir.c +++ b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/remplir.c @@ -1,10 +1,15 @@ #include "remplir.h" +/** + *@fn void remplir(int m) + *@brief Remllit le tableau t avec des valeurs aléatoires + *@param m Limite supérieur pour la création d'un nombre aléatoire +*/ void remplir(int m) { int i = 0; while (i < t.taille) { - t.valeurs[i++] = alea(m); + t.valeur[i++] = alea(m); } } \ No newline at end of file diff --git a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/remplir.h b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/remplir.h index 1ad7694..88454c7 100644 --- a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/remplir.h +++ b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/remplir.h @@ -6,7 +6,6 @@ void remplir(int m); - #endif diff --git a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/alea.c b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/alea.c deleted file mode 100644 index 4a4ad6e..0000000 --- a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/alea.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "alea.h" - -/** - *@fn int alea(int m) - *@brief Génère une valeur aléatoire entre 0 et m - *@param m Limite supérieur pour la création d'un nombre aléatoire - *@return Un entier aléatoire entre 0 et m -*/ -int alea(int m) -{ - return rand() % (m + 1); -} - diff --git a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/io.c b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/io.c deleted file mode 100644 index 2b9cd8b..0000000 --- a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/io.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "io.h" - -/** - * @fn void affiche() - * @brief Affiche les élements du tableau t -*/ -void affiche() -{ - int i; - for (i = 0; i < t.taille; i++) - { - printf("%d\t", t.valeur[i]); - } - printf("\n"); -} \ No newline at end of file diff --git a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/main.c b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/main.c deleted file mode 100755 index 6208348..0000000 --- a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/main.c +++ /dev/null @@ -1,61 +0,0 @@ -/** - *@file main.c - *@brief Programme principale pour trier un tableau dynamique 1D (une dimension) - *@details Ce programme créer un tableau, le remplit avec des valeurs aléatoires, le trie, puis affiche le tableau trié - *@author Pradheep U. - *@date 20/03/2024 - *@version 2.0 - *@copyright Copyright 2024 Pradheep U. -*/ - -#include "tableau.h" -#include "alea.h" -#include "remplir.h" -#include "io.h" -#include "tri.h" - -tableau t; //Déclaraition d'un tableau dynamique - -/** - * @fn int main(argc, char **argv) - * @brief Fonction principale - * @param argc Nombre d'arguments de ligne de commande - * @param argv Tableau des arguements de ligne de commande - * @return 0 en cas de succès, 1 en cas d'échec - * @details Verifie le nombre d'arguments et procéde au remplissage, au tri et à l'affichage du tableau -*/ -int main(int argc, char **argv) -{ - - if (argc < 3) - { - printf("usage : main <nb elems> <max val>\n"); //la valeur maximale que peut prendre une valeur - return 1; - } - - t.taille = atoi(argv[1]); // lecture du 1er argument - - int m = atoi(argv[2]); // lecture du 2eme argument - - - t.valeur = NULL; // initialisation du pointeur - t.valeur = (int *)malloc(t.taille * sizeof(int)); // allocation du tableau - if(t.valeur == NULL) { - fprintf(stderr, "Erreur d'allocation de la mémoire\n"); - exit(EXIT_FAILURE); - } - - remplir(m); // remplissage aléatoire du tableau - - printf("tableau non trié :\n"); - affiche(); - - trier(); - - printf("tableau trié :\n"); - affiche(); - - free(t.valeur); //libération de la mémoire - - return 0; -} diff --git a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/remplir.c b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/remplir.c deleted file mode 100644 index 2f740b8..0000000 --- a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/remplir.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "remplir.h" - -/** - *@fn void remplir(int m) - *@brief Remllit le tableau t avec des valeurs aléatoires - *@param m Limite supérieur pour la création d'un nombre aléatoire -*/ -void remplir(int m) -{ - int i = 0; - while (i < t.taille) - { - t.valeur[i++] = alea(m); - } -} \ No newline at end of file diff --git a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/tri.c b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/tri.c deleted file mode 100644 index 2bf0ae0..0000000 --- a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/src/tri.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "tri.h" - -/** - *@fn void bulle(int k) - *@brief Trie une portion du tableau t en utilisant l'algortithme du tri à bulle - *@param k Limite supérieur pour le tri - *@details Pour éviter l'accès en dehors du tableau, 'i + 1' ne doit pas dépasser 'k'; cette condition est validé par i < k -*/ -void bulle(int k) -{ - int i = 0; - for (i = 0; i <= k; i++) //Pour éviter d'accéder hors du tableau, la boucle dans bulle ne doit pas permettre que 'i + 1' dépasse k. Donc i < k dans la condition du boucle for. - { - // Condition pour un tri décroissant, pour un tri croissant inversé la condition t.valeur[i] > t.valeur[i + 1]) - if (t.valeur[i + 1] > t.valeur[i]) - { - int tmp = t.valeur[i + 1]; - t.valeur[i + 1] = t.valeur[i]; - t.valeur[i] = tmp; - } - } -} - -/** - *@fn void trier() - *@brief Trie le tableau en tableau t en utilisant l'algorithme du tri à bulle -*/ -void trier() -{ - int i = 0; - for (i = t.taille - 1; i >= 0; i--) - { - bulle(i); - } -} \ No newline at end of file diff --git a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/tableau.h b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/tableau.h index d641413..f879e92 100644 --- a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/tableau.h +++ b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/tableau.h @@ -11,7 +11,7 @@ */ typedef struct { - int *valeurs; ///< Pointeur vers le tableau d'entier + int *valeur; ///< Pointeur vers le tableau d'entier int taille; ///< Taille du tableau } tableau; diff --git a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/tri.c b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/tri.c index 94c3a63..f169887 100644 --- a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/tri.c +++ b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/tri.c @@ -1,19 +1,30 @@ #include "tri.h" +/** + *@fn void bulle(int k) + *@brief Trie une portion du tableau t en utilisant l'algortithme du tri à bulle + *@param k Limite supérieur pour le tri + *@details Pour éviter l'accès en dehors du tableau, 'i + 1' ne doit pas dépasser 'k'; cette condition est validé par i < k +*/ void bulle(int k) { int i = 0; - for (i = 0; i <= k; i++) + for (i = 0; i < k; i++) //Pour éviter d'accéder hors du tableau, la boucle dans bulle ne doit pas permettre que 'i + 1' dépasse k. Donc i < k dans la condition du boucle for. { - if (t.valeurs[i + 1] > t.valeurs[i]) - { // echange de t[i] et t[i+1] - int tmp = t.valeurs[i + 1]; - t.valeurs[i + 1] = t.valeurs[i]; - t.valeurs[i] = tmp; + // Condition pour un tri décroissant, pour un tri croissant inversé la condition t.valeur[i] > t.valeur[i + 1]) + if (t.valeur[i + 1] > t.valeur[i]) + { + int tmp = t.valeur[i + 1]; + t.valeur[i + 1] = t.valeur[i]; + t.valeur[i] = tmp; } } } +/** + *@fn void trier() + *@brief Trie le tableau en tableau t en utilisant l'algorithme du tri à bulle +*/ void trier() { int i = 0; diff --git a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/tri.h b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/tri.h index 433c601..1cbcea5 100644 --- a/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/tri.h +++ b/TP3_SUITE_TP2_CLONE/code_modifie/reorganisation/tri.h @@ -3,7 +3,6 @@ #include "tableau.h" - void trier(); void bulle(int k); -- GitLab