Question: C++ Heap Sort using STL libraray 1. Modify t he code below so that it reads and sorts the array from least to greatest, and

C++ Heap Sort using STL libraray

1. Modify the code below so that it reads and sorts the array from least to greatest, and it displays the time in took to run (run time)

You can get the data to test here:

 almostSorted.txt http://faculty.utrgv.edu/robert.schweller/CS2380/homework/notRandom1000000.txt random.txt http://faculty.utrgv.edu/robert.schweller/CS2380/homework/random1000000.txt 

2. Run the code and provide a screenshot showing that it works.

//------------------------------------------------------------------------------------------------

#include

#include

#include

#include

#include

using namespace std;

void heapSort(int * items, unsigned start, unsigned end)

{

priority_queue q;

for (int i = start; i <= end; i++)

{

q.push(items[i]);

}

for (int i = end; i >= start; --i)

{

items[i] = q.top();

q.pop();

}

}

int main()

{

const int size = 1000000;

ifstream read;

ofstream write;

clock_t start;

double duration;

int * arr = new int[size];

read.open("almostSorted.txt");

for (int i = 0; i < size; i++)

{

read >> arr[i];

}

read.close();

start = clock();

heapSort(arr, 0, size - 1);

duration = (std::clock() - start) / (double)CLOCKS_PER_SEC;

cout << "Runtime: " << duration << " seconds" << endl;

write.open("outputALS.txt");

for (int i = 0; i < size; i++)

{

write << arr[i] << endl;

}

write.close();

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!