here is the problem and the selection sort. I am stuck on how to open up the fil
ID: 3568502 • Letter: H
Question
here is the problem and the selection sort. I am stuck on how to open up the file once i have sorted the array to calculate the min, max, average, and median number of swaps. can someone please help?
void sort(double x[], int n)
{
int m;
double hold;
for (int k=0; k<=n-2; ++k)
{
m=k;
for(int j=k+1; j<=n-1; ++j)
{
if (x[j]
m=j;
}
hold=x[m];
x[m]=x[k];
x[k]=hold;
}
return;
}
Explanation / Answer
void SelectionSort(apvector <int> &num)
{
int numm,numm1;
int i, j, first, temp;
int numLength = num.length( );
for (i= numLength - 1; i > 0; i--)
{
first = 0; // initialize to subscript of first element
for (j=1; j<=i; j++) // locate smallest between positions 1 and i.
{
if (num[j] < num[first])
first = j;
}
numm=num[first];
numm1=num[i];
temp = num[first]; // Swap smallest found with element in position i.
num[first] = num[i];
num[i] = temp;
if(numm1!=num[i] && numm!=num[first])
{
count++;
}
}
return;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.