RosettaCodeData/Task/Binary-search/Zkl/binary-search-1.zkl
2017-09-25 22:28:19 +02:00

9 lines
361 B
Text

fcn bsearch(list,value){ // list is sorted
fcn(list,value, low,high){
if (high < low) return(Void); // not found
mid:=(low + high) / 2;
if (list[mid] > value) return(self.fcn(list,value, low, mid-1));
if (list[mid] < value) return(self.fcn(list,value, mid+1, high));
return(mid); // found
}(list,value,0,list.len()-1);
}