SHARE
TWEET

Untitled

a guest May 20th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void main(String[] args)
  2. {
  3.     int[] a = {47,25,77,11,24,17,73,18};
  4.     QuickSort(a, 0, a.Length - 2, a.Length - 1);
  5. }
  6.  
  7. public static void QuickSort(int[] array, int start, int end, int pivot)
  8. {
  9.     if (start >= end) return;
  10.  
  11.     int leftScan = start;
  12.     int rightScan = end;
  13.  
  14.     while (true)
  15.     {
  16.         while (array[leftScan] < array[pivot])
  17.         {
  18.             leftScan++;
  19.         }
  20.  
  21.         while (array[pivot] < array[rightScan])
  22.         {
  23.             rightScan--;
  24.         }
  25.  
  26.         if (leftScan + 1 >= rightScan)
  27.         {
  28.             int temp2 = array[pivot];
  29.             array[pivot] = array[leftScan];
  30.             array[leftScan] = temp2;
  31.             break;
  32.         }
  33.         else
  34.         {
  35.             int temp1 = array[leftScan];
  36.             array[leftScan] = array[rightScan];
  37.             array[rightScan] = temp1;
  38.         }
  39.     }
  40.  
  41.     QuickSort(array, start, leftScan - 1, leftScan - 1);
  42.  
  43.     QuickSort(array, leftScan + 1, end, end);
  44. }
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