#define COMPARE(x,y) (((x)<(y))? -1:(((x)==(y))? 0:1))
int binsearch(array[ ], int left, int right,int searchnum)
{
int middle;
int tmp;
while(left<=right)
{
middle=(left+right)/2;
tmp = array[middle];
switch(COMPARE(searchnum,tmp))
{
case -1: right=middle-1;
break;
case 0: return middle;
case 1:left=middle+1;
}
}
return -1;
}