//c实现 1 #include "stdafx.h" 2 #include "stdlib.h" 3 4 5 int _tmain(int argc, _TCHAR* argv[]) 6 { 7 int a[10] = { 0,1,3,4,6,7,9,11,12,15}; 8 int low,high,mid,key,flag; 9 key = 7;flag = -1;10 low = 0;high = 10; 11 while(lowkey)15 high = mid - 1;16 else if(a[mid]
//lua实现 1 function BinarySearch_t(t,key) 2 local low,flag,high,mid 3 low = 1 4 high = #t 5 flag = -1 6 while(lowkey) then10 high = mid - 111 elseif(t[mid]