hw7.cpp
//Filename: hw7.cpp Class: CS 1570
//Description: Times runs of several sorting algorithms
#include<cstdlib>
#include "hw7.h"
int main()
{
int start, end;
float runTime;
float minTime, maxTime, avgTime;
int array[MAX_SIZE];
greeting();
for(int type = 0; type < NUM_SORTS; type++)
{
fillArray(array, TEST_SIZE, TEST_MIN, TEST_MAX);
cout<<"\nUnsorted Array:"<<endl;
output(array, TEST_SIZE);
sortArray(array, TEST_SIZE, type);
cout<<"\nArray sorted with "<<sortName(type)<<":"<<endl;
output(array, TEST_SIZE);
}
for(int type = 0; type < NUM_SORTS; type++)
{
minTime = 9999999; //Sloppy, but if a sort takes that long, I quit;
maxTime = 0;
avgTime = 0;
for(int j = 0; j < RUNS; j++)
{
fillArray(array, MAX_SIZE, MIN_VAL, MAX_VAL);
start = clock();
sortArray(array, MAX_SIZE, type);
end = clock();
runTime = static_cast<float>(end - start)/CLOCKS_PER_SEC;
if(runTime < minTime)
minTime = runTime;
if(runTime > maxTime)
maxTime = runTime;
avgTime += runTime;
}
avgTime /= RUNS;
showResults(minTime, maxTime, avgTime, type);
}
signoff();
return 0;
}