Using C++ - Insertion Sort - Quick Sort - Merge Sort Test each sort algorithm us
ID: 3846645 • Letter: U
Question
Using C++
- Insertion Sort
- Quick Sort
- Merge Sort
Test each sort algorithm using an array of 10000 elements(use random numbers). Display the time difference using the time function for each sort algorithm. Time it before the function sorting is called.
The following code was posted by Royden Luckey:
Here is how to use current time.
#include <ctime> ... needed.
void timer()
{
clock_t startTime;
clock_t endTime;
double runningTime;
start = clock();
//RUN THE THING YOU WANT TO TIME HERE!!!
end = clock();
runningTime = double(endTime) - double(startTime); //running time is now number of clock ticks on your system
runningTime /= CLOCKS_PER_SECOND; //runningTime is now the number of seconds in real time
cout << " It took " << runningTime << " seconds to run the test. " << endl;
}
Explanation / Answer
#include #include #include #include using namespace std; long length = 1000; const long max_length = 300000; int list[max_length]; void read() { ifstream fin("random.dat", ios::binary); for (long i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.