Re: binary search with reference to append

new topic     » goto parent     » topic index » view thread      » older message » newer message
jaygade said...

I think I finally got the logic right.

For the usage case that you've written this for, it looks good.

However, binary_search() has an extra requirement:

-- # a negative integer, ##-i##, with ##i## between adjusted start and end 
--    points. This means that ##needle## is not in the searched slice of 
--    ##haystack##, but would be at index ##i## if it were there. 
-- # a negative integer ##-i## with ##i## out of the searched range. This 
--   means than ##needle##might be either below the start point if ##i## 
--   is below the start point, or above the end point if ##i## is. 

So it might return, say, -5, if the needle is not in the haystack but index 5 is where the needle should be sorted into.

I guess, sometimes you just can't have it all.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu