Seconds to understand quick sort

Source: Internet
Author: User

Fast sequencing is a sort of algorithm developed by Donny Holl. On average, sort n items to 0 (n log n) comparisons. In the worst case scenario, a 0 (N2) comparison is required, but this is not a common situation. In fact, fast sequencing is usually much faster than the other 0 (n log n) algorithms because its internal loop (inner Loop) can be implemented efficiently on most architectures


Quick Sort Core:"datum" (pivot), partition (partition), swap (swap), recursive (recursive).


Quick Sort Implementation:

/* *AUTHOR:BOOIRROR (AT) 163 (dot) com *date:2015/4/28 */#include <stdio.h>void swap (int a[], int n, int m) {if (n = = m ) Return;int tmp = a[n];a[n] = a[m];a[m] = tmp;}  void qsort (int a[], int n) {int I, j;int last = 0;if (n < 2) Return;swap (A, 0, N/2); for (i = 1; i < n; i++) {if (A[i] < a[0]) {swap (A, ++last, i);}} Swap (A, 0, last): Qsort (A, last); Qsort (a+last+1, n-last-1);} int main () {int i = 0;    int ra[10] = {n    , 1,----------------- Qsort (RA, ten);    while (I <)        printf ("%d", ra[i++]);    Puts ("\ n");    int ar[6] = {4, 6, one, one, one, one, 41};qsort (AR,); for (i=0; i < 6; i++) {printf ("%d", Ar[i]);} Puts ("\ n");    return 0;}

Quick-Sort Process animations:

Finish

Seconds to understand quick sort

Related Article

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.