C #. Net quick Sorting Algorithm

Source: Internet
Author: User
Quick sorting: The algorithm used to search for the internet yesterday. Today, C # is used for implementation. It's really fast.

Simple Description: The first input parameter is the array to be sorted. Here I write the reference transfer and use the ref modifier. In fact, it is not critical to pass the reference here, the second and third Parameters specify the start and end points to be sorted. Of course, they are all sorted in full order. Just point to the array header and end. Pay attention to num. length. Do not forget to subtract one. Otherwise, the array will be out of bounds. The array starts from 0 ~

Private void checknumoredasc (ref int [] num, int left, int right)
{
Int I = left;
Int J = right;
Int temp;
Int middle;
Middle = num [(right + Left)/2];
While (Num [I] <middle) & (I <right ))
{
I ++;
}
While (Num [J]> middle) & (j> left ))
{
J --;
}
If (I <= J)
{
Temp = num [I];
Num [I] = num [J];
Num [J] = temp;
I ++;
J --;
}
If (left <j)
{
Checknumoredasc (ref num, left, J );
}
If (Right> I)
{
Checknumoredasc (ref num, I, right );
}
}

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.