C # bubbling Algorithm review

Source: Internet
Author: User

C # bubbling Algorithm review

Bubble algorithm Meaning: Each trip to find a minimum or maximum number to the last side, compare the total number of n-1 times (because the comparison is 2 both compare)

The second loop represents the first few loops, the number of trips equals the number of comparisons-the number of times (the second trip is less than once, because the smallest one after the first trip)

usingSystem;namespacetest{classProgram { Public Static voidMain () {//bubble algorithm Meaning: Each trip to find a minimum or maximum number put to the last side, compare the total number of n-1 times            inttemp; int[] arr = { at, A, $, -, the, $, the, -, $, -}; //The first layer of loops represents the number of comparisons that are to be compared (number of)-1 times             for(intI=0; I<arr. length-1; i++)            {                //The second loop represents the first few loops, the number of trips equals the comparison-the number of trips (starting from 1) (the second trip is less than once, because the smallest after the first trip is the last one)                 for(intj=0; J<arr. length-1-I.; J + +)                {                    if(Arr[j] > arr[j+1]) {temp=Arr[j]; ARR[J]= arr[j+1]; Arr[j+1] =temp; }                }            }            foreach(intNincharr)            {Console.WriteLine (n);            } console.readkey (); }    }}

C # bubbling Algorithm review

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.