Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Busqueda binaria version recursiva
#include <stdio.h> #define M 6 int busquedaBinariaRec(int *, int, int, int); int main(void) { int A[M] = {10, 20, 30, 40, 50, 60}; int clave = 50; int posicion = busquedaBinariaRec(A, 0, M - 1, clave); if (posicion == -1) printf("%d NO ESTA EN VECTOR", clave); else printf("%d ESTA EN EL VECTOR EN POSICION %d", clave, posicion); return 0; } int busquedaBinariaRec(int * A, int start, int end, int target) { if (start > end) return -1; else { int middle = (start + end) / 2; if (A[middle] == target) return middle; else if (A[middle] > target) return busquedaBinariaRec(A, start, middle - 1, target); else return busquedaBinariaRec(A, middle + 1, end, target); } }
run
|
edit
|
history
|
help
0
Example of scanf and basic integer manipulation - with function call
project menu
a
B_141125_Burbuja
String Manipulation
B_141212_OrdenarArray
string.c
C_141203_CadenasVarias
Assignment 7
cstructVector