1. Re: An useful addition to sort.e

CChris wrote:
> I just took a deeperlook at this "simple" code and tested it. The simple code
> doesn't work:
> if x is outside the interval defined by s[1] and s[$], the returned result
> does not conform to the header comment. If a name list starts at "Craig", you
> won't be able to locate "Bernie" properly. 

It works fine for me...
sequence s
s = {"Craig",
     "Homer",
     "Marge"
    }
? binary_find("Bernie", s)


This returns -1, which means "Bernie" was not found,
but if you insert it now, it will have position 1.

? binary_find(9, {1,3,5,7})

returns -5, meaning 9 was not found, but if you insert it now,
it will have position 5.

The header comment says:
  "If x is not found, the place in s where x would go if it 
   were inserted is returned as a negative index number."

Maybe you can think of a clearer way of stating it.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu