Quick Sort Method

Source: Internet
Author: User

#include <stdio.h>#include<stdlib.h>voidSwapint*PI,int*PJ)//Exchanging Data{    inttemp = *Pi; *PI = *PJ; *PJ =temp;}voidShowint*p,intN//Show Array Status{printf ("\ n This state");  for(inti =0; I < n; i++) {printf ("%4d", P[i]); }}voidQuickint*arr,intILeft,intiright) {    inti = ILeft;//start looping from the left    intj = IRight +1;//start the loop from the right    if(I < J)//If the left is less than the right    {         Do        {             Do{i++; }  while(Arr[i] <= Arr[ileft] && i <iright); //find the first number greater than arr[ileft] from left to right                         Do{J--; }  while(Arr[j] >= Arr[ileft] && j>ileft); //find the first number less than arr[ileft] from right to left//swap if the position of the large number is less than the decimal place            if(I <j) {Swap (&arr[i], &Arr[j]); }            //The goal of this step is to put the big numbers on the right .} while(I < J);//has been circulating to the i>=j description has already been divided into a good time J save is less than Arr[ileft] the number so to and Arr[ileft] ExchangeSwap (&arr[ileft), &Arr[j]); //J is the dividing point, the quick sort on the left and the rightQuick (arr, ILeft, J-1); Quick (arr, J+1, IRight); }}voidMain () {intnum[Ten] = {Ten,9, -, +,1,8,9, A,0, the }; Quick (num,0,9); Show (num,Ten); System ("Pause");}

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.