Advertisement
Guest User

QSort

a guest
Apr 25th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. private void qsort(int[] array, int begin, int end) {
  2.         try {
  3.             if (end > begin) {
  4.                 int index = begin + RAND.nextInt(end - begin + 1);
  5.                 int pivot = array[index];
  6.                 {
  7.                     int tmp = array[index];
  8.                     array[index] = array[end];
  9.                     array[end] = tmp;
  10.                 }
  11.                 for (int i = index = begin; i < end; ++i) {
  12.                     if(index < i/2){
  13.                         if (c.compareSuffixes(array[i], pivot) <= 0) {
  14.                             int tmp = array[index];
  15.                             array[index] = array[i];
  16.                             array[i] = tmp;
  17.                             index++;
  18.                         }
  19.                     }
  20.                     else if (c.compareSuffixes(array[i], pivot) < 0) {
  21.                         int tmp = array[index];
  22.                         array[index] = array[i];
  23.                         array[i] = tmp;
  24.                         index++;
  25.                     }
  26.                 }
  27.                 {
  28.                     int tmp = array[index];
  29.                     array[index] = array[end];
  30.                     array[end] = tmp;
  31.                 }
  32.                 System.out.println("Index : " + index);
  33.                 qsort(array, begin, index - 1);
  34.                 qsort(array, index + 1, end);
  35.             }
  36.         } catch (NotTokenException e) {
  37.             // TODO Auto-generated catch block
  38.             e.printStackTrace();
  39.         }
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement