184k views
2 votes
Read the following Selection Sort function and determine the correct answer for blank #2.

template
int MinIndex(ItemType values[], int startIndex, int endIndex)

// Post: Returns the index of the smallest value in
// values[startIndex]..values[endIndex].
{
int indexOfMin = __________; // 1
for (int index = startIndex + 1; index <= endIndex; index++)
if (values[index] < ________________) // 2
indexOfMin = index;
return indexOfMin;
}

template
void SelectionSort(ItemType values[], int numValues)

// Post: The elements in the array values are sorted by key.
{

int endIndex = ____________; // 3
for (int current = 0; current < endIndex; ___________) // 4
Swap(values[current],
values[MinIndex(values, current, __________)]); // 5

}

a. values[indexOfMin]
b. indexOfMin
c. values[startIndex]

1 Answer

1 vote

Answer:

Option(a) is the correct answer to the given fill in the blank of #2

Step-by-step explanation:

The values[indexOfMin] returns the minimum element in the particular array As in the given question we have to implement the selection sorting .In the selection sorting we have choose the element and compare them others minimum index that's why we have choose the values[indexOfMin] function.

  • The index of min is not the correct function So we have not used in the given fill in the blanks that's why option(b) is incorrect .
  • The values[startIndex] represent the starting index only that is not suitable for the given question that's why it is incorrect option.

User Exabiche
by
7.3k points