I'm trying to solve a problem on a function called "keepsorted";
This function has to keep a sub-list of growing number form a list called l1.
For example if I have let l1 = [1; 2; 0; 1; 2; 4; 3; 5; 3; 2; 6]
the return is a list with the numbers [1; 2; 2; 4; 5; 6]
I tried many solution but I don't understand.
My last solution is:
let rec keepsorted l = match l with | [] -> [] | a1::a2::r when a1 >= a2 -> a1::keepsorted r | a::r -> a::keepsorted r;;
and the result is:
- : int list = [1; 2; 1; 2; 4; 5; 2; 6]