Ok, that's why I am assigned a function
int bin(int value, int size, int array[])
I have to find the "value" inside the "array []", but the problem here is that in most cases we have something like strings
int bin(int value, int max, int min, int array[])
Recursion, logically, is much simpler in this part due to the fact that I can still pass the number I was on, and also remember the size of the array.
int bin(int array[], int value, int min, int max) { if(max < min) return -1; else { int mid = min + (max - min)/2; if(array[mid] > value) return bin(array, value, min, mid-1); else if(array[mid] < value) return bin(array, value, mid+1, max); else return mid; }
But since I can only pass 1 integer, how exactly would I edit this algorithm? Essentially, I could only do something like this, but I KNOW that this will not work logically. Is there a way, however, that I can see the size of the array? I tried, but the numbers do not crunch correctly.
int bin(int array[], int value, int size) { int mid = size/2; if(array[mid] > value) return bin(array, value, size-(size/2)); else if(array[mid] < value) return bin(array, value, size+(size/2)); else return mid; }