This commit is contained in:
2025-09-15 14:27:14 +02:00
parent 2412cd021a
commit 4e34aa3aa6
2 changed files with 61 additions and 2 deletions

View File

@@ -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)
}

View File

@@ -0,0 +1,4 @@
#include <stdio.h>
#include <stdlib.h>