Advertisement
Guest User

is_sorted

a guest
Mar 19th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.44 KB | None | 0 0
  1. (* Write a function is_sorted : string array -> bool which checks if the values of the input array are sorted in strictly increasing order, implying that its elements are unique (use String.compare). *)
  2.  
  3. let rec is_sorted (a: string array) : bool =
  4.   let sub_array = Array.sub a 1 (Array.length a - 1) in
  5.   if sub_array = [||]
  6.   then true
  7.   else if String.compare a.(0) sub_array.(0) > 0
  8.   then
  9.     false
  10.   else
  11.     is_sorted sub_array
  12. ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement