HI everyone, im new to learning C++ language and i would just like to ask how does the binsearch function work, what parameters should i feed into it and an example of input to understand how the whole function works. The binsearch function is as below. Thank you in advance!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int binsearch (char *word, struct key tab[], int n)
{
int cond;
int low, high, mid;
low = 0;
high = n - 1;
while (low <= high) { //Decision 1
mid = (low+high) / 2;
if ((cond = strcmp(word, tab[mid].word)) < 0) //Decision 2
high = mid - 1;
elseif (cond > 0) //Decision 3
low = mid + 1;
elsereturn mid;
}
return -1;
}