Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int busquedaMenorElemento(int arreglo[5],int validos, int pos);
- int busquedaPosMenorElemento(int arreglo[5],int validos, int pos);
- void ordenacionSeleccion(int arreglo[5], int validos);
- int main()
- {
- int notas[5] = {20,15,10,9,1} ; //la primera va con 90 el resto en 0
- int menor = busquedaMenorElemento(notas,5,0);
- int posMenor = busquedaPosMenorElemento(notas,5,0);
- printf("el menor es %d\n",menor);
- printf("la posMenor es %d\n",posMenor);
- ///?????
- ordenacionSeleccion(notas,5);
- for (int indice = 0;indice<5;indice++)
- {
- printf("%d\n",notas[indice]);
- }
- return 0;
- }
- int busquedaMenorElemento(int arreglo[5],int validos, int pos)
- {
- //20
- int menor = arreglo[pos]; //asumo que donde arranco es el menor
- //1
- int indice = pos+1;
- while (indice < validos)
- {
- //20 > 5 // 5 > 10 // 5 > 9 // 5 > 1
- if ( menor > arreglo[indice])
- {
- //5 -- 1
- menor = arreglo[indice];
- }
- indice++;
- }
- return menor;//1
- }
- ///fn para buscar la POS del menor elemento en un arreglo a partir de una posicion determinada
- int busquedaPosMenorElemento(int arreglo[5],int validos, int pos)
- {
- int posMenor = pos; //donde arranco el arreglo
- //20
- int menor = arreglo[posMenor]; //asumo que donde arranco es el menor
- //1
- int indice = pos+1; //para ahorrar un ciclo
- while (indice < validos)
- {
- //20 > 5 // 5 > 10 // 5 > 9 // 5 > 1
- if ( menor > arreglo[indice])
- {
- //5 -- 1
- menor = arreglo[indice];
- posMenor = indice;
- }
- indice++;
- }
- return posMenor;//4 (los pos)
- }
- ///fn para ordenar el arreglo
- void ordenacionSeleccion(int arreglo[5], int validos)
- {
- int posMenor;
- int aux;
- int indice = 0;
- while (indice < validos)
- {
- posMenor = busquedaPosMenorElemento(arreglo,validos,indice);
- aux = arreglo[indice];
- arreglo[indice] = arreglo[posMenor];
- arreglo[posMenor] = aux;
- indice++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement