Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ MODIFICATION ASSIGNMENT You will add some modifications to the code provided. The goal of this exercise to see which sorting algorithm is most efficient.

C++ MODIFICATION ASSIGNMENT You will add some modifications to the code provided. The goal of this exercise to see which sorting algorithm is most efficient. You should come up with different tests, such as using different size arrays. You should randomly generate the large integer arrays (1000+) and have a counter in the code that will count swaps or loops; either will be fine, but be consistent.  
#include  //include correct libraries using namespace std; void quickSort(int arr[], int left, int right) { int i = left, j = right; int tmp; int pivot = arr[(left + right) / 2]; /* 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--; } }; /* recursion */ if (left < j) quickSort(arr, left, j); if (i < right) quickSort(arr, i, right); } void selectSort(int arr[], int n) { int index_min_value; int temp; for (int i=0; i 0 && arr[j] < arr[j-1]) { // move elements over until find the position for next element temp = arr[j]; arr[j] = arr[j-1]; arr[j-1] = temp; j--; } } } void swap(int *xp, int *yp) { int temp = *xp; *xp = *yp; *yp = temp; } void bubbleSort(int arr[], int n) { int i, j; for (i = 0; i < n-1; i++) {// Last i elements are already in place for (j = 0; j < n-i-1; j++){ if (arr[j] > arr[j+1]){ swap(&arr[j], &arr[j+1]); } } } } void printList(int arr[], int length){ for (int i = 0; i//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 myArray1[] = {12, 13, 5, 4, 7, 18, 9 }; int myArray2[] = {12, 13, 5, 4, 7, 18, 9 }; int myArray3[] = {12, 13, 5, 4, 7, 18, 9 }; int myArray4[] = {12, 13, 5, 4, 7, 18, 9 }; cout << endl; cout << " ======== Small array ======= " << endl; cout << endl; cout<<"My original small array is: "<//cout<<"When ordered with selectSort, after "< printList(myArray1,7); //insertionSort insertionSort(myArray2,7);  //cout<<"When ordered with insertionSort, after "< printList(myArray2,7); //bubbleSort bubbleSort(myArray3,7);  //cout<<"When ordered with bubbleSort, after "< printList(myArray3,7); //quickSort quickSort(myArray4,0,6); //cout<<"When ordered with quickSort, after "< printList(myArray4,7); cout << endl; cout << " ======== Large array ======= " << endl; cout << endl;  //Begin with large arrays; test with each case and use the same print statements.  return 0; } 

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

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

More Books

Students also viewed these Databases questions