Quickly sort a shaped array

Source: Internet
Author: User

The quick sort is to find a datum point first, then put the smaller than it to the left (ascending sort), put bigger than it to the right, and then put the datum point to the middle, the last two parts of the array to do the same steps to complete the quick sorting. The program is done in a recursive manner.

Here is the code

 #include <stdio.h>void quicksort (int src[], int  Left, int right) {if  (left >= right) return;int l = left;int r  = right;int key = src[left];while  (L < r) {while  (key  <= src[r] && l<r) r--;src[l] = src[r];while  (key >=  SRC[L]&NBSP;&&&NBSP;L<R) l++;src[r] = src[l];} Src[l] = key;quicksort (src, left, l - 1); Quicksort (Src, l + 1,  right);} Int main () {int i;int a[] = { 1, 5, 6, 3, 4, 9, 95,  32, 56, 45 };quicksort (A, 0, sizeof (a)  / sizeof (A[0])-1);for  (i  = 0; i < sizeof (a)  / sizeof (a[0]); i++) printf ("%d ",  a[i]); System ("pause"); return 0;} 


Quickly sort a shaped array

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.