Quick sorting may feel fast when you hear this name, but the worst time complexity of his algorithm is the same as inserting sorting. The reason for quick sorting is that the average efficiency is faster than the heap sorting, and the fast sorting is based on the grouping idea and the Merge Sorting, but the quick sorting is the original address, you do not need to open up new buckets directly in the original array. The idea of fast sorting is very simple, that is, to select a keyword k to divide the original array into two parts g1 and g2, all elements in g1 are smaller or equal to k, all the data in g2 is larger than k or equal to k. In this way, g1 and g2 are sorted quickly, and what we get is an ordered array. The sort method in the Code is the description of the statement just now. The key algorithm is to find the k position and divide the original array into two parts: size. The getPlocation method is the core of fast sorting. Its implementation principle is a bit like insert sorting, but a little like. Each time, the element at the end position in the map is used as the keyword. The array is divided into two parts by comparison with the end element, while the I and j are two split lines, the number between I and j is a larger element than the core. I and j are like a greedy snake. When the next number of j is larger than the core, j + 1, the length of I to j is increased. If it is smaller than the core, I and j move forward and place the decimal point in front of I. After this loop, the start to end-1 is separated by size, and the core is placed in the middle. The return of the core is the dividing line.
public class QuickSort {public int getPlocation(int[] map,int start,int end){int core=map[end];int i=start-1;for(int j=start;j<=end-1;j++){if(map[j]<=core){i++;int cache=map[j];map[j]=map[i];map[i]=cache;}}i++;map[end]=map[i];map[i]=core;return i;}public void sort(int[] map,int start,int end){if(start