1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| class Solution{ public void quickSort(int[] array,int low,int higth){ if(low < hight){ int partition = getPartition(array,low,higth); quickSort(array,low,partition); quickSort(array,partition+1,hight); } } public int getPartition(int[] array,int low,int higth){ int pivot = array[higth]; int i = low -1; for(int j=low;j< higth;j++){ if(array[j] <pivot){ i++; swap(array,i,j); } } swap(array,i+1,higth); return i; } public void swap(int[] array,int left,int right){ int temp = array[left]; array[left]= array[right]; array[right]= temp; } }
|