没啥好说的,直接上代码:
Position BinarySearch( List L, ElementType X ){
int low = 1,high = L->Last;
while(low <= high){
int mid = (low+high)/2;
if (L->Data[mid] == X){
return mid;
}
else if (L->Data[mid] > X){
high = mid-1;
}
else
low = mid+1;
}
return NotFound;
}