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
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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started