I need help with binary searching arrays, my problem is that I feel like I have all the right requirements but it's not searching at all. I don't get any error messages. Just not getting the results I want. The array is globally initialized as well as the max number of words. This is what my function looks like:
int wordsFindFast(const char const* w){
/*
ROLE Determines whether a given word is in our words array
Implements fast binary search algorithm
PARAMETERS w word to look for in the words array
RETURN VALUE 1 true if the word was found
0 false if the word was not found
*/
int first, middle, last;
first = 0;
last = (MAX_NB_WORDS) - 1;
middle = (first+last)/2;
while(first <= last)
{
if (words[middle] < w){
first = middle + 1;
}//end if
else if(words[middle] == w){
return 1;
}//end else if
else
last = middle - 1;
middle = (first + last)/2;
}//end while
return 0;
}