GonchuB

MergeSort in Oz

Jul 15th, 2013
520
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local A B MyMerge MySplit MyMergeSort in
  2.    fun {MyMerge Xs Ys}
  3.       case Xs#Ys
  4.       of Xs#nil then
  5.      Xs
  6.       [] nil#Ys then
  7.      Ys
  8.       [] (X|Xr)#(Y|Yr) then
  9.      if X<Y then
  10.         X|{MyMerge Xr Ys}
  11.      else
  12.         Y|{MyMerge Xs Yr}
  13.      end
  14.       end
  15.    end
  16.    proc {MySplit Xs ?Ys ?Zs}
  17.       case Xs
  18.       of nil then
  19.      Ys = nil
  20.      Zs = nil
  21.       [] [X] then
  22.      Ys = [X]
  23.      Zs = nil
  24.       [] X1|X2|Xr then Yr Zr in
  25.      Ys = X1|Yr
  26.      Zs = X2|Zr
  27.      {MySplit Xr Yr Zr}
  28.       end
  29.    end
  30.    fun {MyMergeSort Xs}
  31.       case Xs
  32.       of nil then
  33.      nil
  34.       [] [X] then
  35.      [X]
  36.       [] _|_ then Ys Zs in
  37.      {MySplit Xs Ys Zs}
  38.      {MyMerge {MyMergeSort Ys} {MyMergeSort Zs}}
  39.       end
  40.    end
  41.    A = [5 2 6 4 1]
  42.    B = {MyMergeSort A}
  43.    {Browse B}
  44. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×