abr 2, 2009
Enviado por Kalith en C/C++, Programacion
Busqueda binaria c++
Buenas..
Creo que no hay que describir mucho en que consiste el algoritmo de busqueda binaria, aclarar que a la función hay que pasarle el array de elementos ordenandos porque sino no funciona, y el otro parametro es el elemento a buscar.. esta funcion es con numeros enteros pero puede ser con cualquier tipo de dato siempre que esten ordenados.
int busquedaBinaria(int array[], int buscar)
{
//MAX es mi constante del tamaño del arreglo pueden usar lenght
int sup = MAX-1,
inf = 0,
centro;
while(inf < sup)
{
centro = (sup+inf)/2;
if(buscar == array[centro])
return centro;
else
if(array[centro] > buscar)
sup = centro - 1;
else
inf = centro + 1;
}
}
Posts Relacionados
- Enviar emails con Visual C++ .NET Despues de tiempo sin escribir (ya se me acabaron las...
Menciones/Notificaciones
- mobile website dimensions - way. writing a title that target the... emotional hot spots of your target audience is exactly what you need to do ...
- depression testimony - little over three feet long and tend... to look more like a viper than a snake because they have a triangular ...



Que flojo… ordenalo de una vez!!!
Tan facil que es!
Usando