Question: please read the question carefully. Write a C source code module called hw2.c that puts your sort functions to work. hw2.c should define 3 arrays
please read the question carefully.
Write a C source code module called hw2.c that puts your sort functions to work. hw2.c should define 3 arrays at least 15 integers long. Each of the arrays should contain the same integers but the initial sort order should vary. One of the arrays should arrange the numbers in ascending order. One of the arrays should arrange the numbers n descending order. The third array should arrange the numbers in a random order (you get to define what "random" is). The main() function in hw2.c should call each of the sort functions on each of the data sets (9 cases in all) and keep a tally of the results (number of compares and number of swaps) from each sort. Once the program has gathered results from all of the test cases it should display a comparison of the results.
--it should implement a function with the following prototype: int bubbleSort(int arr[], int size, int* ncompares_ptr, int* nswaps_ptr); where arr[] is the integer array to sort, size is the number of elements in the array and ncompares__ptr and nswaps_ptr are pointers to int variables that will be written with the total number of compares performed and the total number of swaps performed to complete the sort. The function should return an integer containing the total number of steps (compares + swaps) required to sort the array.
--it should implement a function with the following prototype: int selectionSort(int arr[], int size, int* ncompares_ptr, int* nswaps_ptr); where arr[] is the integer array to sort, size is the number of elements in the array and ncompares__ptr and nswaps_ptr are pointers to int variables that will be written with the total number of compares performed and the total number of swaps performed to complete the sort. The function should return an integer containing the total number of steps (compares + swaps) required to sort the array.
--it should implement a function with the following prototype: int insertionSort(int arr[], int size, int* ncompares_ptr, int* nswaps_ptr); where arr[] is the integer array to sort, size is the number of elements in the array and ncompares__ptr and nswaps_ptr are pointers to int variables that will be written with the total number of compares performed and the total number of swaps performed to complete the sort. The function should return an integer containing the total number of steps (compares + swaps) required to sort the array.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
