From a153225b25b69eebc87859f6e8e8f8ca224e64a4 Mon Sep 17 00:00:00 2001 From: chafiol <antonin.chafiol@gmail.com> Date: Fri, 13 Mar 2020 15:14:54 +0100 Subject: [PATCH] =?UTF-8?q?FINISHED:=20tri=20bulle=20impl=C3=A9ment=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Algos_1/Lib/main.c | 17 +++++++++++++++++ Algos_1/Tris/triBulle.c | 14 ++++++++++++++ Algos_1/Tris/triBulle.h | 18 ++++++++++++++++++ Algos_1/makefile | 9 ++++++--- 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 Algos_1/Tris/triBulle.c create mode 100644 Algos_1/Tris/triBulle.h diff --git a/Algos_1/Lib/main.c b/Algos_1/Lib/main.c index ba6e932..a93ba23 100644 --- a/Algos_1/Lib/main.c +++ b/Algos_1/Lib/main.c @@ -1,6 +1,7 @@ #include "../Tris/triInsertion.h" #include "../Tris/triFusion.h" #include "../Tris/triRapide.h" +#include "../Tris/triBulle.h" #include "../Lib/utils.h" int main(int argc, char **argv){ @@ -63,6 +64,22 @@ int main(int argc, char **argv){ printf("\n"); free(tab); } + else if((strcmp(argv[1], "--bulle")== 0) || strcmp(argv[1], "-b")== 0){ + int n= 0; + long *tab = readToTab(argv[2], &n); + printf("Base : "); + for(int i = 0; i<n; i++){ + printf("%ld,", tab[i]); + } + printf("\n"); + triBulle(tab, n); + printf("Bulle : "); + for(int i = 0; i<n; i++){ + printf("%ld,", tab[i]); + } + printf("\n"); + free(tab); + } else if (strcmp(argv[1], "-a") == 0) { int n= 0; diff --git a/Algos_1/Tris/triBulle.c b/Algos_1/Tris/triBulle.c new file mode 100644 index 0000000..c3eaa3d --- /dev/null +++ b/Algos_1/Tris/triBulle.c @@ -0,0 +1,14 @@ +#include "triBulle.h" + +void triBulle(long* A, size_t n){ + for(int I = n - 2;I >= 0; I--) { + for(int J = 0; J <= I; J++) { + if(A[J + 1] < A[J]) { + int t = A[J + 1]; + A[J + 1] = A[J]; + A[J] = t; + } + } + } + +} \ No newline at end of file diff --git a/Algos_1/Tris/triBulle.h b/Algos_1/Tris/triBulle.h new file mode 100644 index 0000000..3224f69 --- /dev/null +++ b/Algos_1/Tris/triBulle.h @@ -0,0 +1,18 @@ +#ifndef triBulle_h +#define triBulle_h + +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> + +#include "../Lib/utils.h" + +void triBulle(long* A, size_t n); + +#endif \ No newline at end of file diff --git a/Algos_1/makefile b/Algos_1/makefile index a0fbfc0..299e3cf 100644 --- a/Algos_1/makefile +++ b/Algos_1/makefile @@ -1,11 +1,14 @@ all: tri -tri: Lib/main.c Tris/triInsertion.o Tris/triFusion.o Tris/triRapide.o Lib/utils.o - gcc -Wall Lib/main.c Tris/triInsertion.o Tris/triFusion.o Tris/triRapide.o Lib/utils.o -Wall -o tri +tri: Lib/main.c Tris/triBulle.o Tris/triInsertion.o Tris/triFusion.o Tris/triRapide.o Lib/utils.o + gcc -Wall Lib/main.c Tris/triInsertion.o Tris/triFusion.o Tris/triBulle.o Tris/triRapide.o Lib/utils.o -Wall -o tri insertion: Tris/triInsertion.c Tris/triInsertion.h gcc -c Tris/triInsertion.c Tris/triInsertion.h -Wall +bulle: Tris/triBulle.c Tris/triBulle.h + gcc -c Tris/triBulle.c Tris/triBulle.h -Wall + fusion: Tris/triFusion.c Tris/triFusion.h gcc -c Tris/triFusion.c Tris/triFusion.h -Wall @@ -16,4 +19,4 @@ utils: Lib/utils.c Lib/utils.h gcc -c Lib/utils.c Lib/utils.h -Wall clear: - rm *.o \ No newline at end of file + rm Tris/*.o \ No newline at end of file -- GitLab