Untitled

mail@pastecode.io avatar
unknown
ocaml
2 years ago
364 B
1
Indexable
Never
let rec is_sorted = function
  | [] -> true
  | [_] -> true
  | a::b::t when a <= b -> is_sorted (b::t)
  | a::b::t -> false;;

let rec pass l =
  match l with
    [] -> []
  | [_] -> l
  | a::b::xs when a > b -> b::pass (a::xs)
  | a::b::xs -> a::pass (b::xs);;

let rec bubble l =
  let passed = pass l in
  if is_sorted passed then passed
  else bubble passed;;