RosettaCodeData/Task/Binary-search/R/binary-search-2.r

16 lines
274 B
R
Raw Permalink Normal View History

2013-04-10 12:38:42 -07:00
IterBinSearch <- function(A, value) {
low = 1
high = length(A)
i = 0
while ( low <= high ) {
mid <- floor((low + high)/2)
if ( A[mid] > value )
high <- mid - 1
else if ( A[mid] < value )
low <- mid + 1
else
return(mid)
}
NULL
}