我正在尝试在 Mozart OZ 中实现快速排序,但变量未引入错误出现。我是这种语言的新手。请帮帮我。
declare
fun {QuickSort L}
case L
of X|L2 then Left Right SL SR in
{Partition L2 X Left Right}
SL={QuickSort Left}
SR={QuickSort Right}
{Append SL X|SR}
[] nil then nil
end
end
{Browse {QuickSort[4 7 66 545 1 65 22 322]}}
最佳答案
proc {Partition Xs Pivot Left Right}
case Xs
of X|Xr then
if X < Pivot
then Ln in
Left = X | Ln
{Partition Xr Pivot Ln Right}
else Rn in
Right = X | Rn
{Partition Xr Pivot Left Rn}
end
[] nil then Left=nil Right=nil
end
end
fun lazy {LQuickSort Xs}
case Xs of X|Xr then Left Right SortedLeft SortedRight in
{Partition Xr X Left Right}
{LAppend {LQuickSort Left} X|{LQuickSort Right}}
[] nil then nil
end
end
关于algorithm - 可变分区未在 mozart Oz 中引入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39602641/