19. Bubble sort operation in C #

Source: Internet
Author: User

In front we learned the for Loop, where we use the For loop we learned earlier to implement a bubbling sort operation. Typically, a bubble sort is a small-to-large sort.

Here is the core source code that I implemented:

int[] array_01=New int[Ten];
            Randomrandom_01=New Random();
            // start to create random series
            Console.WriteLine(" Start output Random series:" );
             for(inti=0; i<array_01.length;i++)
            {
array_01[i]=random_01.Next(1,101);
            }
            // output a random sequence
             for(inti=0; i<array_01.length;i++)
            {
                Console.Write(array_01[i]+"\ T");
            }
            // start bubble sort
            //For example:Ten,9,8,7,6,5,4,3,2,1order from left to right, minimum number on left, maximum number on right
            The // outer Loop represents the index of the number that is ready to be determined
             for(inti=0; i<=array_01.length-1; i++)
            {
                The // inner loop represents: Determines the number of times an interchange is required
                 for(intj=1; j<=array_01.length-1-i;j++)
                {
                    // compare to determine if you want to swap
                    if(Array_01[i]>array_01[i+j])
                    {
                        inttemp;
Temp=array_01[i];
Array_01[i]=array_01[i+j];
array_01[i+j]=temp;
                    }
                }
            }
            Console.WriteLine("The result of the comparison is:" );
             Results of//output comparison
             for(inti=0; i<=array_01.length-1; i++)
            {
                Console.Write(array_01[i]+"\ T");
            }


This article is from the "Smile" blog, please be sure to keep this source http://yiyiweixiao.blog.51cto.com/2476874/1970626

19. Bubble sort operation in C #

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.