What is your question?
Looking at the code, a few things come to mind:
- It would be better to use vector<int> instead of arrays. That way you could write
bool readFile(const char *name, vector<int> &numbers)
and have it read all the numbers from the file into the vector, regardless of the file size. You could also pass the vector by itself to the sort functions.
- Passing the vector to the sort functions will avoid the big bug you have: Right now line 23 sorts the array so line 24 is passing the sorted array to insertion_sort. You need to pass the same unsorted data to both sort algorithms.
- In your sort functions, I'd print out the algorithm name, size of the vector, and the sort time, separated by tabs or commas. That will make it much easier to import into a spreadsheet. For example:
- Are you sure that your sorting algorithms are correct? I'd create an
isSorted()
function that checks the vector to ensure it's sorted. Call this in main() after each call to a sort algorithm.