new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
13
Task/Binary-search/Racket/binary-search.rkt
Normal file
13
Task/Binary-search/Racket/binary-search.rkt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#lang racket
|
||||
(define (binary-search x v)
|
||||
; loop : index index -> index or #f
|
||||
; return i s.t. l<=i<h and v[i]=x
|
||||
(define (loop l h)
|
||||
(cond [(>= l h) #f]
|
||||
[else (define m (quotient (+ l h) 2))
|
||||
(define y (vector-ref v m))
|
||||
(cond
|
||||
[(> y x) (loop l (- m 1))]
|
||||
[(< y x) (loop (+ m 1) h)]
|
||||
[else m])]))
|
||||
(loop 0 (vector-length v)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue