aboutsummaryrefslogtreecommitdiff
path: root/6.1.1/key.c
blob: f6384fe472fe2b325e9d88264e24754977863cec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <string.h>
#include "key.h"

struct key *
bsearch(char *word, struct key tab[], int n)
{
	int cond;
	struct key *low, *high, *mid;

	low = tab;
	high = tab + n - 1;
	while (low <= high) {
		mid = low + (high-low) / 2;
		if ((cond = strcmp(word, mid->word)) < 0)
			high = mid - 1;
		else if (cond > 0)
			low = mid + 1;
		else 
			return mid;
	}

	return NULL;
}