Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify your program so that it prints the array at each step of the algorithm. #include using namespace std; void selectionSort(int [], int); void showArray(int

Modify your program so that it prints the array at each step of the algorithm.

#include

using namespace std;

void selectionSort(int [], int); void showArray(int [], int);

int main() {

const int SIZE = 6; int values[SIZE] = {5, 12, 2, 6, 7, 1};

cout << "The unsorted values are "; showArray(values, SIZE);

selectionSort(values, SIZE);

cout << "The sorted values are "; showArray(values, SIZE); return 0; }

void selectionSort(int array[], int size) {

int startScan, maxIndex, maxValue; for (startScan = 0; startScan < (size - 1); startScan++) { maxIndex = startScan; maxValue = array[startScan]; for(int index = startScan + 1; index < size; index++) {

if (array[index] > maxValue) { maxValue = array[index]; maxIndex = index; } } array[maxIndex] = array[startScan]; array[startScan] = maxValue; } }

void showArray(int array[], int size) { for (int count = 0; count < size; count++) cout << array[count] << " "; cout << endl; }

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

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

What criteria must an LLC meet to avoid double taxation?

Answered: 1 week ago