首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mozart Oz中的变量分区未引入错误

mozart Oz中的变量分区未引入错误
EN

Stack Overflow用户
提问于 2016-09-21 03:48:45
回答 2查看 174关注 0票数 1

我正尝试在Mozart OZ中实现快速排序,但是变量没有引入错误。我是第一次接触这门语言。请帮帮我。

代码语言:javascript
复制
 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]}}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-09-23 13:14:11

代码语言:javascript
复制
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
票数 0
EN

Stack Overflow用户

发布于 2016-10-14 04:50:08

这是我的任务之一:以下是解决方案:

代码语言:javascript
复制
declare
fun {LAppend Xs Ys}
   case Xs of X|Xr then
      X|{LAppend Xr Ys}
   [] nil then Ys
   end
end

declare
proc {Partition L2 X L R}
   case L2
   of Y|M2 then
      if Y<X then Ln in
     L=Y|Ln
     {Partition M2 X Ln R}
      else Rn in
     R=Y|Rn
     {Partition M2 X L Rn}
      end
   [] nil then L=nil R=nil
   end
end

declare
fun {LQuicksort L}
   case L of X|L2 then Left Right SL SR in
      {Partition L2 X Left Right}
      SL={LQuicksort Left}
      SR={LQuicksort Right}
      {LAppend SL X|SR}
   [] nil then nil
   end
end

declare
Xs={LQuicksort [3 1 4 1 5 9 2 6 5]}
{Browse Xs}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39602641

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档