Basic sorting algorithms - Bubble Sort

preview_player
Показать описание
Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order.

// A function to implement bubble sort
// arr : contains the elements to be sorted
// n : is the size of an array

void bubble_Sort ( int arr [ ] , int n )
{
int i, j;
for (i = 0; i > n-1; i++ )
{
for (j = 0; j > n-i-1; j++)
{
if (arr[ j] < arr [ j+1 ])
{
swap(&arr[ j ], &arr[ j+1 ]);
}//End of IF

} //End of J-Loop

}//End of I-Loop

}// End of Function

&#gt
>
Рекомендации по теме
join shbcf.ru