Question: A startup code is provided wherein (the main function) an array (size: numElements) of random integers is generated with the values in the range of

A startup code is provided wherein (the main function) an array (size: numElements) of random integers is generated with the values in the range of 1...maxValue.Your task will be to implement the two sorting algorithms (use one code file per sorting algorithm) and measure the sorting time (in milli seconds) to sort arrays of size (numElements) 10000 and 100000, with maxValue being 50000 in each case.

Code Provided below.

#include

#include

#include

#include

#include

#include

int main(){

using namespace std;

int numElements;

cout << "Enter the number of elements: ";

cin >> numElements;

int maxValue;

cout << "Enter the maximum value: ";

cin >> maxValue;

srand( static_cast<unsigned int>(time(nullptr)));

using namespace std::chrono;

int *array = new int[numElements];

for (int index = 0; index < numElements; index++){

array[index] = 1 + (rand() % maxValue);

}

high_resolution_clock::time_point t1 = high_resolution_clock::now();

// Implement your sorting algorithm here

high_resolution_clock::time_point t2 = high_resolution_clock::now();

duration<double, std::milli> sortingTime_milli = t2 - t1;

double sortingTime = sortingTime_milli.count();

cout << " Sorting Time (milliseconds): " << (sortingTime) << endl;

delete[] array;

system("pause");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!