gpt4 book ai didi

algorithm - 可变分区未在 mozart Oz 中引入错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:18:45 25 4
gpt4 key购买 nike

我正在尝试在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com