File #tcrzcy93-6722 - RUBY - Sourcecode

Uploaded by Georg - 05/02/2012 15:56 - 3 Views
Source code
  1. #3a)
  2. def quickSortFromTo!(a,l,r)
  3.     if l >= r then
  4.        return a ;
  5.     else
  6.         nKl = r;
  7.         i = l+1;
  8.         while (i <= nKl)
  9.             if a[i] > a[l] then
  10.                 if a[nKl] < a[l] then
  11.                     # swap
  12.                     swap = a[i];
  13.                     a[i] = a[nKl];
  14.                     a[nKl] = swap;
  15.                     i = i + 1;
  16.                 end
  17.                 nKl = nKl - 1;
  18.             else
  19.                 i = i + 1;
  20.             end;
  21.         end;
  22.         swap = a[nKl];
  23.         a[nKl] = a[l];
  24.         a[l] = swap;
  25.         quickSortFromTo!(a,l,nKl-1);
  26.         return quickSortFromTo!(a,nKl+1,r);
  27.     end;
  28. end;
  29.  
  30. def quickSort!(a)
  31.     return quickSortFromTo!(a,0,a.size-1);
  32. end;