我想知道如何编写一个高效的快速排序版本, 其中列表一次分区。
我有这段代码,
let rec quicksort' = function
[] -> []
| x::xs -> let small = List.filter (fun y -> y < x ) xs
and large = List.filter (fun y -> y > x ) xs
in quicksort' small @ (x :: quicksort' large);;
但在这里,我浏览列表不止 1 次(对小型和大型调用 2 次快速排序)。
我们的想法是只需一步即可完成,而不需要超过 1 次。