-1

The following OZ program uses the built-in partition function in order to perform the QuickSort algorithm. It is required to modify the program by using the original partition schemes instead of the built-in partition function. I searched and found 2 original schemes: Lomuto partition scheme and Hoare partition scheme, but I am not able to modify the program (I am new to OZ language)! The required two partition schemes are explained in Wikipedia in the following link: https://en.wikipedia.org/wiki/Quicksort

The OZ program that I am trying to modify:

declare fun {QuickSort Xs} case Xs of nil then nil [] Pivot|Xr then fun {IsSmaller X} X

Adam
  • 11
  • 1
    declare fun {QuickSort Xs} case Xs of nil then nil [] Pivot|Xr then fun {IsSmaller X} X – Adam Sep 09 '16 at 07:56

1 Answers1

1
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
Usman Maqbool
  • 3,351
  • 10
  • 31
  • 48
Dhrumit
  • 26
  • 3