#include <iostream>
using namespace std;
const int sz = 10;
void leerDatos( int v[] );
void ordenarDatos( int v[] );
void imprimirDatos( const int v[] );
int buscar( const int v[], int valor );
int main()
{
int numeros[sz];
int buscado, pos;
cout << "\nIntroducir datos:\n";
leerDatos( numeros );
ordenarDatos( numeros );
cout << "\nDatos ordenados: ";
imprimirDatos( numeros );
cout << "\nNumero a buscar: ";
cin >> buscado;
pos = buscar( numeros, buscado );
(pos == -1 ? cout << "No encontrado" : cout << "Encontrado en la posicion " << pos);
cout << endl;
return 0;
}
void leerDatos( int v[] )
{
for( int i = 0; i < sz; i++ ) {
cout << "(" << i + 1 << "/" << sz << "): ";
cin >> v[i];
}
}
void ordenarDatos( int v[] )
{
int valor;
int j;
for(int i = 1; i < sz; i++) {
valor = v[i];
j = i;
while( j > 0 && valor < v[j-1] ) {
v[j] = v[j-1];
j--;
}
v[j] = valor;
}
}
void imprimirDatos( const int v[] )
{
for( int i = 0; i < sz; i++ )
cout << v [i] << " ";
cout << endl;
}
int buscar( const int v[], int buscado )
{
int pos = 0;
while( pos < sz && v[pos] != buscado ) {
pos++;
}
if (pos >= sz) {
pos = -1;
}
return pos;
}