Code:
#include <stdio.h>
int
BinarySearch(int *asize, int numbers[*asize], int *snum, int *searcher, int *iter, int *top, int *bottom, int *middle, int *found)
{
*middle = (int)(((*top + *bottom)/2.0)+.5);
printf("top = %d middle = %d bottom = %d\nsearcher = %d snum = %d &numbers[*middle] = %d found = %d", *top, *middle, *bottom, *searcher, *snum, numbers[*middle], *found);
if(*bottom < *top && *found == 0) {
if(searcher == numbers[*middle]) {
*found = 1;
*iter++;
printf("found %d", &numbers[*middle]);
}
else if(numbers[*middle] > *searcher) {
*top = *middle - 1;
printf("top = %d middle = %d bottom = %d\nsearcher = %d snum = %d &numbers[*middle] = %d", *top, *middle, *bottom, *searcher, *snum, numbers[*middle]);
printf("calling function recursively");
return (BinarySearch(*asize, numbers, *snum, *searcher, *iter, *top, *bottom, *middle, *found));
}
else {
*bottom = *middle + 1;
printf("top = %d middle = %d bottom = %d\nsearcher = %d snum = %d &numbers[*middle] = %d", *top, *middle, *bottom, *searcher, *snum, numbers[*middle]);
return (BinarySearch(*asize, numbers, *snum, *searcher, *iter, *top, *bottom, *middle, *found));
}
}
else{}
if(*found == 1) {
return(0);
}
else {
printf("top = %d middle = %d bottom = %d\nsearcher = %d snum = %d &numbers[*middle] = %d", *top, *middle, *bottom, *searcher, *snum, numbers[*middle]);
}
}