Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 591

Workaround to append attaching elements in reverse order when sorting

$
0
0

I want to sort so that odd numbers in a list appeart first and evens appear last, but i need evens to be the same position to how they were pre sort, is there a simple workaround to this?

let rec first_odd list = match list with| [] -> []| h::t when h mod 2==0 -> first_odd t@[h]| h::t -> h::first_odd t;;first_odd[3;1;7;3;4;5;4;3;6;-1;0;3];;first_odd[1;0;1;5;6;6;1;10;-8;4; -9];;

Viewing all articles
Browse latest Browse all 591

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>