diff --git a/bubblesort.c b/bubblesort.c index 2fb0d04..0dffd4d 100644 --- a/bubblesort.c +++ b/bubblesort.c @@ -1,8 +1,7 @@ // Bubblesort Algorithm // M.Menault 2024 -void bubblesort(int* array, int length) -{ +void bubblesort(int* array, int length){ int swapped, i, tmp; do { @@ -23,3 +22,59 @@ void bubblesort(int* array, int length) + + + +int swapped, i, tmp; + do + { + swapped = 0; + for(i=1;i array[i]) + { + tmp = array[i-1]; + array[i-1] = array[i]; + array[i] = tmp; + swapped++; + } + } + } while(swapped==1); +} + + + int * test = (int*) malloc(length*sizeof(int)); + int max = -1; + for (j=1;jmax){ + indice = i ; + max =array[i]; + } + } + test[indice]=max; + array[indice]=-1; + } + for (j=1;j array[i]) + { + tmp = array[i-1]; + array[i-1] = array[i]; + array[i] = tmp; + swapped++; + } + } + } while(swapped==1) +} + diff --git a/short.c b/short.c index e69de29..9093717 100644 --- a/short.c +++ b/short.c @@ -0,0 +1,4 @@ +#include +#include + +