#define CMP(a,b) ((a==b)?0:(a<b)?-1:1)
#define uint32 int
#define ARRAY_SIZE 100
int my_array[ARRAY_SIZE];
void ArraySort(int This[], uint32 the_len)
{
/* selection sort */
uint32 indx;
uint32 indx2;
uint32 large_pos;
int temp;
int large;
if (the_len <= 1)
return;
for (indx = the_len - 1; indx > 0; --indx)
{
/* find the largest number, then put it at the end
of the array */
large = This[0];
large_pos = 0;
for (indx2 = 1; indx2 <= indx; ++indx2)
{
temp = This[indx2];
if (CMP(temp ,large) > 0)
{
large = temp;
large_pos = indx2;
}
}
This[large_pos] = This[indx];
This[indx] = large;
}
}
void fill_array()
{
int indx;
for (indx=0; indx < ARRAY_SIZE; ++indx)
{
my_array[indx] = rand();
}
/* my_array[ARRAY_SIZE - 1] = ARRAY_SIZE / 3; */
}
int main() {
int indx;
fill_array();
ArraySort(my_array, ARRAY_SIZE);
for (indx=1; indx < ARRAY_SIZE; ++indx) {
if (my_array[indx - 1] > my_array[indx]) {
printf("bad sort\n");
return(1);
} else {
printf("%d, ",my_array[indx-1]);
}
}
return(0);
}