Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include using namespace std; void printArr(const int a[], int s); void swapVals(int& v1, int& v2); int findMin(const int a[], int s, int from); void sortArr(int

#include  using namespace std; void printArr(const int a[], int s); void swapVals(int& v1, int& v2); int findMin(const int a[], int s, int from); void sortArr(int a[], int s); int main() { const int s = 20; int arr[s] = {8, 38, 25, 4, 47, 47, 38, 36, 3, 33, 2, 19, 16, 30, 5, 47, 16, 38, 13, 1}; cout  

image text in transcribed

Lab 09 Array Sorting: Selection Sort Objective To practice working with arrays. Tasks Implement the findMin and sortArr functions in the provided code file findMin takes three arguments: the array as a, the size of the array as s, and the index that you should start searching at as from. This function should start by looking at the index from and go to the end of the array. Once it has determined what the index of the smallest value between from and s is, it should return that index. If the index provided for from is invalid (larger than or equal to s), return -1 instead. sortArr takes two arguments: the array as a, and the size of the array as s Implement selection sort for this function. The selection sort algorithm divides the input list into two parts: the subarray of items already sorted, which is built up from left to right at the front (left) of the array, and the subarray of items remaining to be sorted that occupy the rest of the array Initially, the sorted subarray is empty and the unsorted subarray is the entire input array. The algorithm proceeds by finding the smallest element in the unsorted subarray, exchanging (swapping) it with the leftmost unsorted element (putting it in sorted order), and moving the subarray boundaries one element to the right. This algorithm performs directly on the array passed to the function. You will not need decided unsorted and sorted arrays since you can just use the array passed in to the function. NOTE: Wikipedia has a good animation of the process in the Selection Sort article. The printArr and swapvals functions have already been implemented. So has main. Make use of the swapvals function when implementing your selection sort Sample output: Console (note: no user interaction needed) Unsorted array: 38 36 3 33 2 19 16 30 5 47 16 38 13 1 8 38 25 4 47 47 Sorted Array 1 2 3 4 5 8 13 16 16 19 25 30 33 36 38 38 38 47 47 47 Procedure 1. In CodeBlocks, create a new project on a flashdrive. 2. Save lab09.cpp to your project folder and rename it to lab09 yourlastname.cpp 3. In Code Blocks, remove main.cppfrom the project and add labo9 yourlastname.cpp to your project. Save the project 4. Perform the tasks outlined above. Make sure you can generate the sample output. 5. When you are done working on the lab, upload labo9 your lastname .cpp to blackboard (from the assignment page, click Browse My Computer) and submit the assignment

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

Prepare an ID card of the continent Antarctica?

Answered: 1 week ago

Question

What do you understand by Mendeleev's periodic table

Answered: 1 week ago

Question

1. Identify the sources for this conflict.

Answered: 1 week ago