Permalink
Browse files

add binary search for Array

  • Loading branch information...
1 parent 9e0e2e1 commit 1b4dcecbec8cb7d9a84ede2accdcf88a34d42349 @ZhangHanDong committed Mar 19, 2011
Showing with 2 additions and 1 deletion.
  1. +2 −1 lib/ruby_extendsions/array_extendsions.rb
@@ -48,9 +48,10 @@ def binary_search_index(e, l = 0, u = length - 1)
return if l>u
m=(l+u)/2
return if !(e.class == self[m].class)
- (e < self[m] ? u=m-1 : l=m+1)
+ e < self[m] ? u=m-1 : l=m+1
e == self[m] ? m : binary_search_index(e,l,u)
end
+
# 基于二分查找的include?
def b_include?(e)
!self.binary_search_index(e).nil?

0 comments on commit 1b4dcec

Please sign in to comment.