SHARE
TWEET

Untitled

a guest Jul 21st, 2019 132 in 13 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q12210709112
  3. このプログラムの流用による不具合の責任を上記URLの回答者・質問者・サイト
  4. 運営者に問うことはできません。
  5. */
  6. public static void quickSort(int[] data){
  7. int[] Left = new int[data.length];
  8. int[] Right= new int[data.length];
  9. int index = 0;
  10.     Left[index] = 0;
  11.     Right[index] = data.length - 1;
  12.     while(index>= 0){
  13.     int left = Left[index];
  14.     int right = Right[index];
  15.         if(left>=right) {index--;continue;}
  16.     int pivot = data[(left+right)/2];
  17.         for(;;){
  18.             while(data[left] < pivot)left++;
  19.             while(data[right] > pivot)right--;
  20.             if(left < right){
  21.             int tmp = data[left];
  22.                 data[left] = data[right];
  23.                 data[right] = tmp;
  24.                 left++;right--;
  25.                 continue;
  26.             }
  27.             break;
  28.         }
  29.         Left[index+1]=Left[index];
  30.         Right[index+1]=(left-1>Left[index])?left-1:Left[index];
  31.         Left[index]=(right+1<Right[index])?right+1:Right[index];
  32.         index++;
  33.     }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top