Advertisement
Guest User

Qsort

a guest
Apr 25th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1.     private void qsort(int[] array, int begin, int end) {
  2.             if (end > begin) {
  3.                 int index = begin + RAND.nextInt(end - begin + 1);
  4.                 int pivot = array[index];
  5.                 {
  6.                     int tmp = array[index];
  7.                     array[index] = array[end];
  8.                     array[end] = tmp;
  9.                 }
  10.                 for (int i = index = begin; i < end; ++i) {
  11.  
  12.                     if (c.compareSuffixes(array[i], pivot) <= 0) {
  13.                         int tmp = array[index];
  14.                         array[index] = array[i];
  15.                         array[i] = tmp;
  16.                         index++;
  17.                     }
  18.                 }
  19.                 {
  20.                     int tmp = array[index];
  21.                     array[index] = array[end];
  22.                     array[end] = tmp;
  23.                 }
  24.                 System.out.println("Index : " + index);
  25.                 qsort(array, begin, index - 1);
  26.                 qsort(array, index + 1, end);
  27.             }
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement