An improvement of the bubble sort in the quick sort, if the initial record sequence is ordered or basically ordered by the keyword, degenerate to bubble sort.
Basic ideas
By a lying sort of data to be sorted into separate two parts, one part of all the data is smaller than the other part of all the data, and then the second method of the two parts of the data are quickly sorted, the entire sorting process can be recursive, so as to achieve the entire data into an ordered sequence.
A trip to the sorting process is as follows:
Specific code
public class QuickSort {public static void main (string[] args) {//TODO auto-generated method stubint[] List = {4,6,1,7,9, 10,2,56,24,0,3}; QuickSort qs = new QuickSort () qs.quicksort (list, 0, list.length-1); for (int i=0; i<list.length; i++) { System.out.print (list[i]+ "");}} public void QuickSort (int[] list, int. Low, int.) {if (Low < high) {int middle = getmiddle (list, low, high); QuickSort (l ist, low, middle-1); QuickSort (list, middle+1, High);}} public int getmiddle (int[] list, int. Low, Int. high) {int tmp = list[low];//Select the first number as pivot while (low < high) {//Use an index to traverse the entire sequence from backward forward while (Low < high && List[high] > tmp) {high--;} List[low] = list[high];while (Low < high && List[low] < tmp) {low++;} List[high] = List[low];} List[low] = Tmp;return low;}}
Performance Analysis
The average performance is the best among all orders of the same order of magnitude O (NLONGN). In terms of average time, it is currently considered to be the best internal sorting method.
Improved
Pivot selection
Pivot selection has a direct effect on the performance of fast sorting, and the worst case scenario is the partitioning of two extremely asymmetric sub-sequences (one length of 1 and another length of n-1), at which point the complexity is O (n*n). You can select the median in the first and middle elements as the pivot, reducing the possibility of dividing the asymmetry.
Java enables quick sorting