Optimized for some details 10% faster than the previous quick row
/** * @authorCLY * Quick Sort*/ Public classMyquicksort {/*** Treats row array sort (ascending) *@paramarr Queue Array *@paramThe starting position of the pivot pivot in the array to be sorted (sort start bit) *@paramend bit of this quick row (sort end bit)*/ Public Static voidSortint[] arr,intPivotintend) { intTmp_pivot =pivot; intTmp_end =end; //true when pivot is to the left of the array, false on the right BooleanFlag =true; //The whole process is the end toward the pivot. while(tmp_pivot!=tmp_end) { if(flag) {//pivot on the left . while(tmp_pivot<tmp_end) { //If it is, the pivot is swapped to the right, and the number is changed to the left, which is smaller than the pivot. if(arr[tmp_pivot]>Arr[tmp_end]) { intTMP =Arr[tmp_pivot]; Arr[tmp_pivot]=Arr[tmp_end]; Arr[tmp_end]=tmp; intTmp_index =Tmp_pivot; Tmp_pivot=Tmp_end; Tmp_end=Tmp_index; Tmp_end++; Break; }Else{//find the last number on the right to see if it's smaller than the pivottmp_end--; }} Flag=false; }Else{//pivot on the right . while(tmp_pivot>tmp_end) { //If it is, the pivot is swapped to the left, and the number larger than the pivot is swapped to the left. if(arr[tmp_pivot]<Arr[tmp_end]) { intTMP =Arr[tmp_pivot]; Arr[tmp_pivot]=Arr[tmp_end]; Arr[tmp_end]=tmp; intTmp_index =Tmp_pivot; Tmp_pivot=Tmp_end; Tmp_end=Tmp_index; Tmp_end--; Break; }Else{//find the next left number to see if it's bigger than the pivottmp_end++; }} Flag=true; } } //at this point the number of the pivot to the left is smaller than it, the number on the right is larger than it. //if the entire array length is less than 2, it means that it is in the bottom line. if(end-pivot<2) { return; } //if the current pivot is to the right of the starting point, it means that there are values on the left side of the pivot, which can be quickly if(tmp_pivot>pivot) {sort (arr, pivot, Tmp_pivot-1);//make a quick row of the number on the left } //if the current pivot is to the left of the end point, it indicates a value on the right side of the pivot, which can be quickly if(tmp_pivot<end) {sort (arr, Tmp_pivot+1, end);//to the right of the number of fast row } }}
Java enables quick sorting