Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type SortType =
- | Ascending
- | Descending
- | Unknown
- | NoSort
- let rec isCurrentlySorted lastItem collectionTail currentSortType =
- match collectionTail with
- | [] -> currentSortType
- | head :: tail ->
- let suggestedSortType =
- if head = lastItem then currentSortType
- elif head > lastItem then Ascending
- else Descending
- if suggestedSortType = Unknown || suggestedSortType = currentSortType then isCurrentlySorted head tail currentSortType
- elif currentSortType = Unknown then isCurrentlySorted head tail suggestedSortType
- else NoSort
- let isSorted collection =
- let currentSort = match collection with
- | [] -> NoSort
- | [single] -> Unknown
- | head :: tail -> isCurrentlySorted head tail Unknown
- match currentSort with
- | Ascending -> "Yes, ascending"
- | Descending -> "Yes, descending"
- | Unknown -> "ХЗ"
- | _ -> "No"
- isSorted [1;2;3]
- isSorted [3;2;1]
- isSorted [3;3;3]
- isSorted [1;2;2;3]
- isSorted [3;2;2;1]
- isSorted []
- isSorted [2]
- isSorted [1;2;2;2;3]
- isSorted [3;2;3;1]
- isSorted [3;2;2;2;0;2;-1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement