Created my own sorting routine in Ocaml.
"Douglas Lewit [email protected] [ocaml_beginners]" <[email protected]> Sun, 17 Apr 2016 14:40:29 -0500
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <CAM0XMJQnz=KGyuTciOsjdWTNCF96mSzR01Pq=SZ+DrC6Abu7nw@mail.gmail.com> |
Its efficiency is perhaps questionable, but I'm proud of it nonetheless because it's an original work. Any feedback is appreciated. Thanks, Douglas. *(* The following is a sort function of my own design. I'm kind of proud of it, but not sure of its efficiency. *)* *let rec sort lst = let remoov element list = let index = ref 0 in * *let rec remove elem l = if !index = 1 then l * *else * *match l with * *|[ ] -> [ ]* *|_ -> if ( List.hd l ) = elem && !index = 0 then begin incr index ; remove elem ( List.tl l ) end else * *( List.hd l ) :: ( remove elem ( List.tl l ) ) in* *remove element list in * *let minimum list = * *let rec minimum_ value l = match l with * *|[ ] -> value * *|head :: tail -> if head < value then minimum_ head tail else minimum_ value tail in * *minimum_ max_int list in * *match lst with * *|[ ] -> [ ]* *|_ -> let min_ = minimum lst in * *min_ :: ( sort ( remoov min_ lst ) ) ;;*