Summary of Java Basic sorting algorithm (II.)--Quick Sort method

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.