#include <stdio.h>
#define TRUE 1
#define FALSE 0
typedef unsigned char BOOL;
typedef unsigned int UINT;
void bubble_sort(UINT*, UINT);
void print_arr(UINT*, UINT);
int main(int argc, char* argv[])
{
int arr[] = {1, 0, 2, 3, 5, 4, 6, 8, 7, 9};
printf("Before sort: ");
print_arr(arr, sizeof(arr)/sizeof(UINT));
bubble_sort(arr, sizeof(arr)/sizeof(UINT));
printf("After sort: ");
print_arr(arr, sizeof(arr)/sizeof(UINT));
return 0;
}
void bubble_sort(UINT* arr, UINT arr_len)
{
UINT i;
UINT j;
UINT temp;
BOOL exchange_flag;
exchange_flag = TRUE;
for(i=0; i<(arr_len-1) && exchange_flag; i++)
{
exchange_flag = FALSE;
for(j=0; j<(arr_len-i-1); j++)
{
if(arr[j] < arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
exchange_flag = TRUE;
}
}
}
}
void print_arr(UINT* arr, UINT arr_len)
{
UINT i;
for(i=0; i<arr_len; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
}