Standard sorting functions in SML?

后端 未结 5 733
夕颜
夕颜 2020-12-11 02:21

Are there standard sorting functions in SML? The documentation on the Internet is so scarce I couldn\'t find any.

5条回答
  •  借酒劲吻你
    2020-12-11 03:06

    here is my sml sorting algorithm

    fun sort list = foldr (fn (x,lst)=> List.filter (fn a => a < x) lst @ [x] @ List.filter (fn a => a >= x) lst ) [] list;
    
    sort [5,1,5,0,2,5,~2,5,~10,0];
    
    output: [~10,~2,0,0,1,2,5,5,5,5]
    

    I hope it helps

提交回复
热议问题