C # bubble algorithm!

Source: Internet
Author: User

After taking multiple tests, I got a bubble Algorithm for several times, one for C # and the other for javascript.
Although I made it through my understanding of the bubble method every time, it is more or less different from the standard mode. I found the C # bubble algorithm on the Internet, there is no sample. I carefully wrote a C # version against the algorithm mode, and the test was successful.
Together with the [bubble sort animation demo]
Public void BubbleSort (int [] R)
{
Int I, j, temp;
// Exchange flag
Bool exchange;
// Sort the R. Length-1 bits at most
For (I = 0; I <R. Length; I ++)
{
// The exchange flag should be false before the sorting starts.
Exchange = false;
For (j = R. Length-2; j> = I; j --)
{
// Exchange conditions
If (R [j + 1] <R [j])
{
Temp = R [j + 1];
R [j + 1] = R [j];
R [j] = temp;
// If an exchange occurs, the exchange flag is set to true.
Exchange = true;

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.