Common sorting algorithms-fast sorting (C language + VC6.0 platform) and vc6.0 Algorithm

Source: Internet
Author: User

Common sorting algorithms-fast sorting (C language + VC6.0 platform) and vc6.0 Algorithm

Quick sorting in classic sorting algorithms is efficient, but its implementation is relatively difficult to understand.

# Include <stdio. h>

Int partition (int num [], int low, int high) // use the key as the benchmark to list the "high" and "low" columns, the data in the "high" part is larger than the key, and the data in the "low" part is smaller than the 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 quick sorting

{

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 };

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 ");

}

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.