]In chapter 10, the book claims that the heap sort algorithm usually takes twice
ID: 3551383 • Letter: #
Question
]In chapter 10, the book claims that the heap sort algorithm usually takes twiceas long as the quick sort algorithm. Do you believe it? Use the code providedby the book, and capture the running time for both algorithms for several differentinputs. Are you able to validate that statement? Write your comments. Submityour code and the running times too.
This is the code and how would I include ctime and where would I put the code.
Also what is the code for ctime.
//Data: 34 77 26 51 39 8 12 67 4 98 123 10 42 -999
#include <iostream>
#include <ctime>
#include "arrayListType.h"
using namespace std;
void printListInfo(arrayListType<int>& list);
int main()
{
arrayListType<int> intList;
int num;
cout << "Enter numbers ending with -999" << endl;
cin >> num;
while (num != -999)
{
intList.insert(num);
cin >> num;
}
cout << "The list you entered is: " << endl;
printListInfo(intList);
intList.quickSort();
cout << "The list after sorting: " << endl;
printListInfo(intList);
return 0;
}
Explanation / Answer
clock_t t; //A clock instatiation
t = clock(); //Starts the clock and saves time at this moment in t
for(int i=0;i<10000;i++) intList.quickSort(); //do this many times
t = clock() - t; //calling clock() again gives you time and by removing previous time we'll get duration.
cout << "It took "<< ((float)t)/CLOCKS_PER_SEC << "seconds for quick sort. ",);
Since I dont have "arrayListType.h" files I can't run the program for you.But the above snippet will help you get things done.
Here 's the link for your code: http://kopasite.net/up/cr3u24g7fmxi386/mergesort.cpp
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.