Question: in c + + program Lab Project 2 : Shellsort Shellsort, also known as Shell sort or Shell's method, is an in - place comparison

in c++ program Lab Project 2: Shellsort Shellsort, also known as Shell sort or Shell's method, is an in-place comparison sort. It can be seen as either a generalization of sorting by exchange (bubble sort) or sorting by insertion (insertion sort). The method starts by sorting pairs of elements far apart from each other, then progressively reducing the gap between elements to be compared. By starting with far apart elements, it can move some out-of-place elements into position faster than a simple nearest neighbor exchange. Donald Shell published the first version of this sort in 1959. The running time of Shellsort is heavily dependent on the gap sequence that it uses. For this project, write the following three functions in the file soln_func.cc: void shell_sort(int array[], int n); This function sorts an array of n integers in ascending order using the Shellsort algorithm. Files We Give You: A makefile and a sample main program (shellsort.cpp) to test your solution. The executable file created by a successful build will be named shellsort. In addition, several sample data files have been provided that can be used as redirected standard input to test your program. The data files are named random6.txt, random8.txt, random16.txt, etc., with the numeric part of the file name specifying the number of random values that the file contains. File You Must Submit: Place your solution code in a file named solution.cpp. This will be the only file that you submit. A more detailed description of the Shellsort algorithm can be found on Wikipedia at the link above. Pseudocode for the Shellsort algorithm written as a generalization of insertion using Martin Ciuras gap sequence is given on the following page. This pseudocode uses the same logic as the version of the algorithm on Wikipedia.Shellsort Pseudocode procedure shell_sort(array : list of sortable items, n : length of list)// i, j, g : loop indexes // gap : current gap value // temp : temporary storage // Define the Ciura gap sequence as an array of int. int gaps[8]=701,301,132,57,23,10,4,1; // Start with the largest gap and work down to a gap of 1.// Similar to insertion sort but instead of 1, gap is being // used in each step. g 0 while g <8 gap gaps[g]// Do a gapped insertion sort for every element in the gaps // array. Each iteration leaves array[0...gap-1] in gapped // order. i gap while i < n // Save array[i] in temp and make a hole at position i. temp array[i]// Shift earlier gap-sorted elements up until the current // location for array[i] is found. j i while j >= gap and array[j-gap]> temp array[j]= array[j-gap] j j gap end while // Put temp (the original array[i] in its correct location. array[j] temp i i +1 end while g g +1 end while end procedure code to fix: #include #include using std::cin; using std::cout; using std::endl; using std::setw; static int build_array(int[]); static void print_array(int[], int); void shell_sort(int[], int); int main() int array[1000]; int n; n = build_array(array); cout << n <<" elements unsorted"; print_array(array, n); cout << endl << n <<" elements in ascending order"; shell_sort(array, n); print_array(array, n); return 0; int build_array(int array[]) int n =0; while (cin >> array[n]) n++; return n; void print_array(int array[], int n) int i; for (i =0; i < n; i++) cout << setw(8)<< array[i]; if ((i+1)

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!