// 3a.cpp
#include <iostream>
#include <iomanip>
using namespace std;
const int CAPACIDAD = 10;
typedef int Arreglo[CAPACIDAD];
void ordenamiento_por_seleccion(Arreglo arreglo, int indice_inicial);
int indice_del_maximo(Arreglo arreglo, int indice_inicial);
void mostrar(Arreglo arreglo);
int main() {
Arreglo notas = {8, 9, 20, 19, 10, 12, 15, 11, 17, 16};
cout<<"Arreglo de notas:"<<endl;
mostrar(notas);
cout<<"\nArreglo ordenado decrecientemente:"<<endl;
ordenamiento_por_seleccion(notas,0);
mostrar(notas);
}
void ordenamiento_por_seleccion(Arreglo arreglo, int indice_inicial) {
if (indice_inicial == CAPACIDAD-1)
return;
else {
int indice = indice_del_maximo(arreglo, indice_inicial);
int max = arreglo[indice];
arreglo[indice] = arreglo[indice_inicial];
arreglo[indice_inicial] = max;
ordenamiento_por_seleccion(arreglo, indice_inicial + 1);
}
}
int indice_del_maximo(Arreglo arreglo, int indice_inicial) {
int indice = indice_inicial;
for (int j=indice_inicial+1; j<CAPACIDAD; ++j) {
if (arreglo[j] > arreglo[indice])
indice = j;
}
return indice;
}
void mostrar(Arreglo arreglo) {
for (int j=0; j<CAPACIDAD; ++j) {
cout<<setw(4)<<arreglo[j];
}
cout<<endl;
}