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

C++ code help!

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//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

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!