Fast sorting algorithm

Source: Internet
Author: User

Pay attention to understanding the division and recursive thinking, select a base (Dig a pit), from right to left to find a smaller than the base of the exchange, and then from left to right to find a larger than the base to exchange.

Java:

public static void Adjustarray (integer[] arr, int l, int r) {if (L < r) {int i = l, j = r;   int k = Arr[l];    while (I < J) {while (I < J && K < Arr[j]) {j--;    } Arr[i] = Arr[j];    while (I < J && k > Arr[i]) {i++;   } Arr[j] = Arr[i];   } Arr[i] = k;   Adjustarray (arr, L, i-1);  Adjustarray (arr, i + 1, R); } }

Reference:

Sorting algorithm--Quick sort

Fast sorting algorithm

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.