Record: algorithm Bubble Sorting

Source: Internet
Author: User

Class Program {// <summary> // Bubble Sorting // core idea: a round of sorting. Compare the size of the two numbers in the array, if the number in front is greater than the number in the back, switch the location, and so on until the I-1 wheel is complete, change the unordered number // group to an ordered array /// </summary> /// <param name = "args"> </param> static void Main (string [] args) {// first prepare an unordered array int [] ary = new int [] {5, 3,}; // start sorting. I indicates the number of rounds, A total of ary. length-1 round for (int I = 0; I <ary. length-1; I ++) {// j indicates the number of times in each round and the number of times in each round. for (int j = 0; j <ary. length-1-i; j ++) {// core of the bubble sort, two numbers compared, the front is greater than the back of the number, if (ary [j]> ary [j + 1]) {// defines a temporary variable to store ary [j] int temp = ary [j]; // switch position ary [j] = ary [j + 1]; ary [j + 1] = temp ;}}} // print the elements in the sorted array for (int I = 0; I <ary. length; I ++) {Console. writeLine (ary [I]) ;}}

This article is from the "Lanting drunk beauty" blog and is not reposted!

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.