/* bbl_slct.c PUBLIC DOMAIN part 2 of 2 */
void show_array(int *array, int max)
{
int i;
for (i = 0; i < max; i++)
printf("%4d", array[i]);
}
int main(void)
{
int table[10] = { 70, 21, 49, 7, 63, 42, 14, 56, 35, 28 };
float elapsed_time;
int test;
puts("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("\n\n Unsorted array is ::");
show_array(table, 10);
puts("\n\n\tA demostration selection sort.");
selectionsort(table, 10);
printf("\n Ascending sort array ::");
show_array(table, 10);
selectionsort(table, -10);
printf("\n\n Descending sort array ::");
show_array(table, 10);
elapsed_time = (float)clock();
for(test = 0; test < 10000; test++)
{
selectionsort(table, 10);
selectionsort(table, -10);
}
elapsed_time = ((float)clock() - elapsed_time)
/ (float)CLOCKS_PER_SEC;
printf("\n\n\t10,000 reversal sorts require %.3f seconds.\n",
elapsed_time);
puts("\n\n\tA demostration of bubble sort.");
bubblesort(table, 10);
printf("\n Ascending sort array ::");
show_array(table, 10);
bubblesort(table, -10);
printf("\n\n Descending sort array ::");
show_array(table, 10);
elapsed_time = (float)clock();
for(test = 0; test < 10000; test++)
{
bubblesort(table, 10);
bubblesort(table, -10);
}
elapsed_time = ((float)clock() - elapsed_time)
/ (float)CLOCKS_PER_SEC;
printf("\n\n\t10,000 reversal sorts require %.3f seconds.\n",
elapsed_time);
puts("\nHit a key to continue...");
getch();
return 0;
}
/* end bbl_slct.c PUBLIC DOMAIN part 2 of 2 */
> ] Nothing is absolute, save Grace, Harmony, and Balance.......
---
---------------
* Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)
|