Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun binsearch x seq lower upper =
- let
- val half = lower + (upper - lower)div 2
- val current_val = Seq.nth seq half
- in
- case (Int.compare(upper, lower),Int.compare(current_val, x)) of
- (LESS, _ ) => lower
- | ( _ , EQUAL) => half
- | ( _ , LESS) => binsearch x seq lower (half)
- | ( _ , GREATER) => binsearch x seq (half + 1) upper
- end
Add Comment
Please, Sign In to add comment