TD1_DEV51_Qualite_Algo/bubblesort.c

30 lines
415 B
C
Raw Normal View History

2024-09-03 08:26:03 +02:00
// Bubblesort Algorithm
// M.Menault 2024
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])
{
2024-09-03 12:18:42 +02:00
/*tmp = array[i-1];
2024-09-03 08:26:03 +02:00
array[i-1] = array[i];
2024-09-03 12:18:42 +02:00
array[i] = tmp;*/
swap(array[i-1],array[i]);
2024-09-03 08:26:03 +02:00
swapped++;
}
}
} while(swapped==1);
}
2024-09-03 12:18:42 +02:00
void swap(int a, int b)
{
int temp = a;
a = b;
b = temp;
}