forked from menault/TD1_DEV51_Qualite_Algo
hahah
This commit is contained in:
59
bubblesort.c
59
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<length;i++)
|
||||
{
|
||||
if(array[i-1] > 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;j<length;j++){
|
||||
int indice = 0;
|
||||
for(i=1;i<length;i++){
|
||||
if(array[i]>max){
|
||||
indice = i ;
|
||||
max =array[i];
|
||||
}
|
||||
}
|
||||
test[indice]=max;
|
||||
array[indice]=-1;
|
||||
}
|
||||
for (j=1;j<length;j++){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
swapped = 0;
|
||||
for(i=1;i<length;i++)
|
||||
{
|
||||
if(array[i-1] > array[i])
|
||||
{
|
||||
tmp = array[i-1];
|
||||
array[i-1] = array[i];
|
||||
array[i] = tmp;
|
||||
swapped++;
|
||||
}
|
||||
}
|
||||
} while(swapped==1)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user