✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
Considere a seguinte classe
1 // Classe que ordena uma array de objectos em ordem
2 // decrescente utilizando o insertionSort.
3
4 template<class T, int size=10>
5 class Sorter {
6 public:
7 Sorter(T arr[], int s=size)
8 : length(s)
9 { // construtor
10 for (int i = 0; i < length; i++)
11 a[i] = arr[i];
12 }
13
14 ...
15 void selectionSort();
16 private:
17 int length;
18 T a[size];
19 // Trocar a[i] e a[j] na array a.
20 void swap(int i, int j)
21 {
22 <código 1>
23 }
24 };
Considere o método selectionSort() dessa classe
26 // Ordenar a array a em ordem decrescente, utilizando selectionSort.
27 // Pré-condição: a é uma array de elementos comparáveis.
28
29 template<class T, int size>
30 void Sorter<T,size>::selectionSort()
31 {
32 for (int i = 0; i < length - 1; i++)
33 {
34 // Encontrar o maior no intervalo a[i+1] a a[n-1]
35 T max = a[i];
36 int maxPos = i;
37 for (int j = i + 1; j < length; j++)
38 // a[j] é ainda maior
39 if (max < a[j])
40 {
41 max = a[j];
42 maxPos = j;
43 }
44 // Troca a[i] e a[maxPos]
45 swap(i, maxPos);
46 }
47 }
Se uma array de tipo int, contiver os elementos 89, 42, -3, 13, 109, 70, 2, qual das seguintes configurações representará a array, depois da terceira passagem do referido método, na ordenação da array por ordem descendente?