Re: Search algorithm



Richard Heathfield said:

<snip>

while left <= right and haystack[guess] <> needle
guess = (left + right) / 2
if haystack[guess] < needle
left = guess + 1
else if haystack[guess] > needle
right = needle - 1

right = guess - 1

Sorry about that.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.



Relevant Pages