Question: Week 2 Lab Activities This lab provides more practice with array - related tasks and sorting algorithms. The main function has been set up to

Week 2 Lab Activities
This lab provides more practice with array-related tasks and sorting algorithms.
The main function has been set up to declare an array with the capacity of your choice.
The "library. h" file contains two function prototypes: display and insertion sort. The "library.cpp" file contains their corresponding function definitions.
You are asked to complete the following three parts:
Part I of this lab is for you to process some array elements.
You are required to randomly initialize an array with the capacity of your choice in main. You are then required to implement the reverse function in the "library.cpp" file and thoroughly test it in "main.cpp".
vold reverse (int arr (1, int n;
This function is to reverse the first n elements of an array without using another array. The following shows the before and after content of two example arrays.
Before: ,1357642
After: ,2467531
Belore: ,1234
After: ,4321
Part II of this lab is for you to trace the insertion sort function.
First, run the program to generate two sets of 5 random numbers. For each set of numbers, trace the insertion_sort function and show your work on keeping track of the following:
The values of i and j.
The number of comparisons between two numbers.
The number of times two numbers must swap positions.
Part III of this lab is for you to modify the insertion sort function. The current implementation of the insertion_sort requires some unnecessary comparisons. Update the insertion_sort function so that when a number is inserted into an appropriate position in a pass, there is no need to make more comparisons.
In addition, the function needs to tally and display the number of comparisons, the number of swaps, and the intermediate array elements for each pass of the outer loop. Below is a sample run:
 Week 2 Lab Activities This lab provides more practice with array-related

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!