Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Binary-search/Ol/binary-search.ol
Normal file
15
Task/Binary-search/Ol/binary-search.ol
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
(define (binary-search value vector)
|
||||
(let helper ((low 0)
|
||||
(high (- (vector-length vector) 1)))
|
||||
(unless (< high low)
|
||||
(let ((middle (quotient (+ low high) 2)))
|
||||
(cond
|
||||
((> (vector-ref vector middle) value)
|
||||
(helper low (- middle 1)))
|
||||
((< (vector-ref vector middle) value)
|
||||
(helper (+ middle 1) high))
|
||||
(else middle))))))
|
||||
|
||||
(print
|
||||
(binary-search 12 [1 2 3 4 5 6 7 8 9 10 11 12 13]))
|
||||
; ==> 12
|
||||
Loading…
Add table
Add a link
Reference in a new issue