csci2041/public-class-repo/SamplePrograms/ordered_list.ml
Michael Zhang 399845160c
f
2018-01-29 17:35:31 -06:00

14 lines
334 B
OCaml

let rec place e l = match l with
| [ ] -> [e]
| x::xs -> if e < x then e::x::xs
else x :: (place e xs)
let rec is_elem e l = match l with
| [ ] -> false
| x::xs -> e = x || (e > x && is_elem e xs)
let rec sorted l = match l with
| [ ] -> true
| x::[] -> true
| x1::x2::xs -> x1 <= x2 && sorted (x2::xs)