A quick sort of the classic sorting algorithm (C language version)

Source: Internet
Author: User

Fast sorting is a very common sort algorithm.

/* * Quick Sort (pseudo algorithm)  2016-04-20 23:34:16 * 1. First find the final position of the first element  * 2. The element before the final position of the first element, For quick sorting.  * 3. Quickly sorts the elements after the final position of the first element.  **/extern void quicksort (Int a[],int low,int high);//The second parameter represents the subscript of the first element, The third parameter represents the subscript Extern intfindpos (Int a[], int low, int high) of the last element; Extern int  findpos (int a[], int start, int end) {int val;val = a[start]; while  ( start < end ) {while  (  (start < end )   &&  ( a[end] > val )  ) {--end;} a[start] = a[end];while  (  ( start < end )  &&  (  a[start] < val )  ) {++start;} A[end] = a[start];} A[start] = val;return start;} Extern void quicksort (int a[], int start, int end) {int pos;// A place that often goes wrong 1. Here should be judged by ifInstead of a loop. if  (start < end) {pos = findpos (a, start, end); QuickSort (a, start, pos - 1); QuickSort (A, pos + 1, end);}}


This article is from the "Do Your best" blog, so be sure to keep this source http://qiaopeng688.blog.51cto.com/3572484/1766040

A quick sort of the classic sorting algorithm (C language version)

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.