online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
/* programa en C++ para implementar la búsqueda binaria recursiva */ #include <bits/stdc++.h> using namespace std; // Una función de búsqueda binaria recursiva. Devuelve // la ubicación de x en el arreglo dado arr[l..r] , // si no está presente devuelve -1 int binarySearch(int arr[], int l, int r, int x) { if (r >= l) { int mid = l + (r-l)/2; // Si el elemento está presente en el medio retorna el indice if (arr[mid] == x) return mid; // Si el elemento es más pequeí±o que mid, entonces // solo puede estar presente en el subarreglo izquierdo if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); // De lo contrario, el elemento solo puede estar presente // en el subarreglo derecho return binarySearch(arr, mid + 1, r, x); } // Llegamos aquí cuando el elemento no está // presente en la matriz return -1; } int main(void) { int arr[] = { 2, 3, 4, 10, 40 }; int x = 4; int n = sizeof(arr) / sizeof(arr[0]); int result = binarySearch(arr, 0, n - 1, x); (result == -1) ? cout<<"El Elemento no esta presente en el arreglo" : cout<<"El Elemento está presente en el indice: "<<result; return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue