0
我试图用榆树榆树快速排序的可视化
显示快速排序的排序过程[ 5, 8, 6, 2, 4, 1, 0, 3, 10, 7, 9 ]
[2,4,1,0,3] 5 [8,6,10,7,9]
[1,0] 2 [4,3] [6,7] 8 [10,9]
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
现在,我可以拿到第2行,但我不能确定如何在递归的方式接近这一点。
list_to_html : List (List Int) -> Html msg
list_to_html x =
div [] [ x |> toString |> text ]
quicksort_partition : List Int -> Html msg
quicksort_partition list =
case list of
x :: xs ->
let
lower =
List.filter ((>=) x) xs
higher =
List.filter ((<) x) xs
in
list_to_html [ lower, [ x ], higher ]
[] ->
list_to_html []
此输出:
[ 5, 8, 6, 2, 4, 1, 0, 3, 10, 7, 9 ]
[2,4,1,0,3] [5] [8,6,10,7,9]