Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add binary search for Array

  • Loading branch information...
commit 1b4dcecbec8cb7d9a84ede2accdcf88a34d42349 1 parent 9e0e2e1
@ZhangHanDong authored
Showing with 2 additions and 1 deletion.
  1. +2 −1  lib/ruby_extendsions/array_extendsions.rb
View
3  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?
Please sign in to comment.
Something went wrong with that request. Please try again.