Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Binary-search/Standard-ML/binary-search.ml
Normal file
17
Task/Binary-search/Standard-ML/binary-search.ml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
fun binary_search cmp (key, arr) =
|
||||
let
|
||||
fun aux slice =
|
||||
if ArraySlice.isEmpty slice then
|
||||
NONE
|
||||
else
|
||||
let
|
||||
val mid = ArraySlice.length slice div 2
|
||||
in
|
||||
case cmp (ArraySlice.sub (slice, mid), key)
|
||||
of LESS => aux (ArraySlice.subslice (slice, mid+1, NONE))
|
||||
| GREATER => aux (ArraySlice.subslice (slice, 0, SOME mid))
|
||||
| EQUAL => SOME (#2 (ArraySlice.base slice) + mid)
|
||||
end
|
||||
in
|
||||
aux (ArraySlice.full arr)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue