In the online forum to see a lot of examples, fast sorting algorithm is the company interview written test of an algorithm, and in peacetime practical application of the manifestation and implementation process is also very good, I think the idea of fast sorting method is based on the bubble sorting method, bubble sorting method is to compare the adjacent elements to the exchange of elements to sort, The fast ordering rule, by determining a datum element, is to recursively sort the elements that are larger or smaller, and the concrete implementation results are somewhat like the concept of dichotomy. Use a picture of the internet here to further explain
, first we take the first element 57 as the datum point, first compared with the last element of the array, the 57>19 is exchanged to the high position, then compared with the second bit of the array 57<69,57 switched to the low, and 69 to the high, once compared to the upper and lower arrays are sorted respectively.
The following is an analysis with specific code:
/* * @Author: Richardwe * @description: Quick Sort Method */public class QuickSort {public static void main (string[] args) {int a[] = { (A, 0, a.length-1); for (int i = 0; i < a.length; i++) {System.out.print),};quicksort,. ln (a[i]);}} Take the first and last one for judging Datum point A, 0, 8public static void QuickSort (int[] list, int low, int.) {if (Low < high) {int middle = ge Tmiddle (list, low, high); Divides the list array into quicksort (list, low, middle-1); Recursive ordering of low-word tables quicksort (list, middle + 1, high); Recursive ordering of high-character tables}}public static int getmiddle (int[] list, int low, int higher) {int temp = List[low];//49while (< h) {while (Low < high && List[high] >= temp) {high--;} List[low] = List[high]; Records that are smaller than the middle axis are moved to the low side while (lower < high && List[low] <= temp) {low++;} List[high] = List[low]; A record larger than the middle axis moved to the high end}list[low] = temp; The middle axis is recorded to the tail return low; }}
Summary of Java Basic sorting algorithm (ii)--quick Sort method