Browse files

add binary search for Array

  • Loading branch information...
1 parent 2f2e5b9 commit 9e0e2e1b368a64a71f97ff21c03a60664011170a @ZhangHanDong committed Mar 19, 2011
Showing with 0 additions and 2 deletions.
  1. +0 −2 lib/ruby_extendsions/array_extendsions.rb
View
2 lib/ruby_extendsions/array_extendsions.rb
@@ -43,7 +43,6 @@ def is_blank_all?
def random
return self[rand(self.size)]
end
-
# 二分查找返回数组index
def binary_search_index(e, l = 0, u = length - 1)
return if l>u
@@ -52,7 +51,6 @@ def binary_search_index(e, l = 0, u = length - 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 9e0e2e1

Please sign in to comment.