Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this part of the lab, you will write a program that uses a different implemen

ID: 3668489 • Letter: I

Question

In this part of the lab, you will write a program that uses a different implementation of selection sort from the one you chose before: If you had chosen to search for the minimum for the traverse of the array, now choose the maximum, or If you had chosen to search for the maximum for the traverse of the array, now choose the minimum. You may choose whether to traverse the array forward or backward. Also, this time you are requested to calculate the number of swaps used to complete sorting the array. You can write a program starting from the previous one, and modify It to sort the array using another selection sort implementation. Once the array is sorted, output first to the console if the output is sorted in ascending or descending order (depending on what you decided to use): "This Is the sorted array In an ascending or descending> order:" and then output the array in a newline. Also, write if you chose the max or min for the traverse (which should be the opposite of sortArrayl.cpp):

Explanation / Answer

#include<iostream.h>

#include<conio.h>

int main()

{

const int sizeA ;

int array[sizeA];

int i,j;

int count=0;

int min, max;

cout<<"please enter number of array elements";

cin>>sizeA;

cout<<"enter array elements";

for(i=0;i<sizeA;i++)

{

cin>>array[i];

}

cout<<"this is sorted array in ascending order";

cout<<"I have choosen minimum for the array traverse";

for(i=0;i<sizeA;i++)

{

min= array[i];

for(j=i+1; j<sizeA;j++)

{

if(array[j] < min)

{

temp= array[j];

array[j] = min;

min= temp;

count++;

} //end of if

} // end of inner for

} // end of outer for

cout<<"The elements are:";

for(i=0;i<sizeA;i++)

{

cout<<" "<<array[i];

}

cout<<"the array is sorted in"<<count<<"number of times";

return 0;

} // end of main method

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote