Common sorting algorithm--quick sort (C language +vc6.0 platform)

Source: Internet
Author: User

The fast sequencing in the classical sorting algorithm has good efficiency, but its realization is relatively difficult to understand.

#include <stdio.h>

int partition (int num[],int low,int High)//key for the column to be ranked as a "tall", "low" two parts, "high" part of the data is larger than key, "low" part of the data is smaller than key

{

int Left,right,key;

Left=low;right=high;key=num[low];

while (Left<right)

{

while (Left<right && Num[right]>=key)

right--;

Num[left]=num[right];

while (Left<right && Num[left]<=key)

left++;

Num[right]=num[left];

}

Num[left]=key;

return left;

}

void Quick_sort (int num[],int low,int High)//recursive implementation Quick sort

{

if (Low

{

int pos=partition (Num,low,high);

Quick_sort (NUM,LOW,POS-1);

Quick_sort (Num,pos+1,high);

}

}

int main ()

{

int data[10]={32,33,21,14,36,7,6,4,2,11};

int i;

for (i=0;i<10;i++)

printf ("%d", data[i]);

printf ("\ n");

Quick_sort (data,0,9);

for (i=0;i<10;i++)

printf ("%d", data[i]);

printf ("\ n");

}

Common sorting algorithm--quick sort (C language +vc6.0 platform)

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.