1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include "myHeader.h"
void headerStars()
{
for (int headerStars = 0; headerStars < 40; headerStars++)
cout << "*";
}
void headerSpaces()
{
for (int headerSpaces = 0; headerSpaces < 9; headerSpaces++)
cout << " ";
}
void programTitle()
{
cout << "Sorting - Time Analysis" << endl;
}
void addRandomNumbers(int defaultArray[], int size)
{
for (int randomNum = 0; randomNum < size; randomNum++)
defaultArray[randomNum] = rand();
}
void doSort (string sortName, void (*sort_func)(int *, int), int* defaultArray, int size)
{
clock_t start, end;
long timeElapsed;
addRandomNumbers (defaultArray, size);
start = clock();
(*sort_func)(defaultArray,size);
end = clock();
timeElapsed = (end-start)/CLOCKS_PER_SEC;
cout << sortName << "Elapsed time (in seconds): " << timeElapsed << endl;
}
int main()
{
int defaultArray[10000];
headerSpaces();
programTitle();
headerStars();
cout << endl;
srand(NULL); // Random Number Seed
doSort ("Small Bubble", bubbleSort, defaultArray, smallSize);
doSort ("Medium Bubble", bubbleSort, defaultArray, mediumSize);
doSort ("Large Bubble", bubbleSort, defaultArray, largeSize);
doSort ("Small Selection", selectionSort, defaultArray, smallSize);
doSort ("Medium Selection", selectionSort, defaultArray, mediumSize);
doSort ("Large Selection", selectionSort, defaultArray, largeSize);
doSort ("Small Insertion", insertionSort, defaultArray, smallSize);
doSort ("Medium Insertion", insertionSort, defaultArray, mediumSize);
doSort ("Large Insertion", insertionSort, defaultArray, largeSize);
cin.get();
cin.ignore();
return 0;
} // End of int main()
|