Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want to compare the runtimes and swap operations times among quick Sort, selection Sort and shell Sort here is my code: But when I

I want to compare the runtimes and swap operations times among quick Sort, selection Sort and shell Sort

here is my code:

But when I create a 1000,000 size array, I can't get the result of the operations times and runtime. what's wrong with my code? and I also want to copy the array. Because I want to use same array for three sort. And for the shell Sort, I haven't learn it in my class. Can anyone help me to add this part?

#include #include #include using namespace std; static int count = 0;

int quickSort(int arr[], int left, int right) { int i = left, j = right; int tmp; int pivot = arr[(left + right) / 2]; //int count =0; /* partition */ while (i <= j) { while (arr[i] < pivot) i++; while (arr[j] > pivot) j--; if (i <= j) { tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; i++; j--; count++; } };

/* recursion */ if (left < j) quickSort(arr, left, j); if (i < right) quickSort(arr, i, right); return count; } int selectSort(int arr[], int n) {

int index_min_value; int temp; int count=0; for (int i=0; i

} if (index_min_value != i) { temp = arr[i]; arr[i] = arr[index_min_value]; arr[index_min_value] = temp; count++; } } return count; } void swap(int *xp, int *yp) { int temp = *xp; *xp = *yp; *yp = temp; } void printList(int arr[], int length){ for (int i = 0; i

} cout<

int main(){ //HINT: You should place a counter into each algorithm to see how many time each of them run. Then you can compare them easier. //You should use the given print statements for better organization. int count = 0; int myArray1[] = {12, 13, 5, 4, 7, 18, 9 }; int myArray2[] = {12, 13, 5, 4, 7, 18, 9 }; //selectSort int start = clock(); count = selectSort(myArray1,7); int stop = clock();

cout<<"When ordered with selectSort, after "<

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago