Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/Binary-search/Scheme/binary-search.ss
Normal file
11
Task/Binary-search/Scheme/binary-search.ss
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(define (binary-search value vector)
|
||||
(let helper ((low 0)
|
||||
(high (- (vector-length vector) 1)))
|
||||
(if (< high low)
|
||||
#f
|
||||
(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))))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue