Advertisement
xXx_Fortis_xXx

Untitled

Jun 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.50 KB | None | 0 0
  1. function Result = quickSort (Q, sortCond)
  2.     right = length(Q);
  3.     left = 1;
  4.     if (left < right)
  5.         mid = floor((left + right)/2);
  6.         i = left;
  7.         j = right;
  8.         supp = Q(mid);
  9.         while (i <= j)
  10.             while (sortCond(Q(i), supp) == 1)
  11.                 i++;
  12.             end
  13.             while (sortCond(supp, Q(j)) == 1)
  14.                 j--;
  15.             end
  16.             if (i <= j)
  17.                 t = Q(i);
  18.                 Q(i) = Q(j);
  19.                 Q(j) = t;
  20.                 i++;
  21.                 j--;
  22.             end
  23.         end
  24.         Result = [quickSort(Q(1:i-1), sortCond) quickSort(Q(i:right), sortCond)];
  25.     else
  26.         Result = [Q];
  27.     end
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement