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 Lab Activities
This lab provides more practice with arrayrelated tasks and sorting algorithms.
The main function has been set up to declare an array with the capacity of your choice.
The "library. 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 int ;
This function is to reverse the first elements of an array without using another array. The following shows the before and after content of two example arrays.
Before:
After:
Belore:
After:
Part II of this lab is for you to trace the insertion sort function.
First, run the program to generate two sets of random numbers. For each set of numbers, trace the insertionsort function and show your work on keeping track of the following:
The values of i and
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 insertionsort requires some unnecessary comparisons. Update the insertionsort 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:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
