1. Algorithmic thinking
Split the sorted data into separate two parts, one of which is smaller than all the data in the other part,
Then the second method of the two parts of the data are quickly sorted, the entire sorting process can be recursive, in order to achieve the entire data into an ordered sequence.
2. Algorithm diagram
3. Implementing the Code
Static voidQuiksort (intN[],intLeftintRight ) { intTemp//to define a temporary variable if(Left <Right ) {Temp= Partition (n, left, right);//assigns the value returned by the partition to tempQuiksort (n, left, temp-1);//Recursive call continues the number of rows to the leftQuiksort (N, temp + 1, right);//Recursive call continues the number of rows to the right } } Static intPartitionintN[],intLeftintRight ) { intPivot = N[left];//take the first number on the left as the base//Loop Right-to-left, pointer movement finds the first number less than pivot while(Left < right && N[right] >=pivot) { Right--; } if(Left < right)//after finding the first number less than pivotn[left++] = N[right];//fill this number in n[left] This position, left forward one block /*The If section above is simplified as follows: if (left < right) {N[left] = N[right]; left++; Note: The use of the + + operator: To assign a value first and then to add it*/ //loop from left to right, the pointer moves to find the first number greater than pivot while(Left < right && N[left] <=pivot) { Left++; } if(Left < right)//find the first number greater than pivotn[right--] = N[left];//fill this number in n[right] This position, right forward a grid//simplify with the same reasoning /*if (left < right) {N[right] = N[left]; right--; Note-The use of the operator: first assignment, then self-subtraction}*/N[left]= pivot;//when exiting, I equals J, the pivot is filled in, the number is divided into two parts, the number on the left is less than pivot, the number on the right is greater than pivot returnLeft//returns the division position}
Classical Sorting algorithm Learning (Java implementation)