Guest User

Untitled

a guest
Jun 25th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. fun binsearch x seq lower upper =
  2. let
  3. val half = lower + (upper - lower)div 2
  4. val current_val = Seq.nth seq half
  5. in
  6. case (Int.compare(upper, lower),Int.compare(current_val, x)) of
  7. (LESS, _ ) => lower
  8. | ( _ , EQUAL) => half
  9. | ( _ , LESS) => binsearch x seq lower (half)
  10. | ( _ , GREATER) => binsearch x seq (half + 1) upper
  11. end
Add Comment
Please, Sign In to add comment