Re: Euphoria Standard Library

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

-- finds x in s, which is assumed to be sorted
-- if x is not found returns the negative of the position where it would be
inserted (like EDS)

global function find_sorted(object x,sequence s)
    integer min,max,mid,test
    min=1
    max=length(s)
    while min<=max do
         mid=floor((min+max)/2)
         test=compare(x,s[mid])
         if test=0 then return mid end if
         if test>0 then
             min=mid+1
         else
             max=mid-1
         end if
   end while
   return -min
end function


-- Mike Nelson

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

Search



Quick Links

User menu

Not signed in.

Misc Menu