blob: 33757eee1251227fc91b5690d3ffd934881e239c (
plain) (
tree)
|
|
#include <string.h>
#include "key.h"
int bsearch(char *word, struct key tab[], int n)
{
int cond;
int low, high, mid;
low = 0;
high = n - 1;
while (low <= high) {
mid = (low+high)/2;
if ((cond = strcmp(word, tab[mid].word)) < 0)
high = mid - 1;
else if (cond > 0)
low = mid + 1;
else
return mid;
}
return -1;
}
|