Invocation of two bubbling sort methods

Source: Internet
Author: User

Class Program {static int[] method (int[] arr)//Method one, first to determine the maximum value, from the back to the front row {for (int i = arr. Length-1; i > 0; i--) {for (int j = 0; J < arr. Length-1; J + +) {if (Arr[j] > arr[j + 1]) {int k = a                        RR[J];                        ARR[J] = arr[j + 1];                    Arr[j + 1] = k;        }}} return arr; } static int[] Method2 (int[] arr)//Method Two, first determine the minimum value, from going to the back row {for (int i = 0; i < arr. Length-1;i + +) {for (int j = i; J <= arr. length-1;j++) {if (Arr[i] > Arr[j]) {in                        t k = arr[i];                        Arr[i] = Arr[j];                    ARR[J] = k;        }}} return arr; } static void Main (string[] args) {int[] arr = new INT[18];                for (int i = 0;i <= 17;i + +) {Random rd = new random ();                Thread.Sleep (200); Arr[i] = Rd.            Next (100);            } foreach (int i in arr) console.write (i + "");            Console.Write ("\ n");            Using method One output result Console.WriteLine ("Method one output from small to large:");            arr = Method (arr);            foreach (int i in arr) console.write (i + "");            Using the method two output results Console.WriteLine ("\ n method two outputs from small to large:");            arr = Method2 (arr);            foreach (int i in arr) console.write (i + "");        Console.ReadLine (); }    }

Invocation of two bubbling sort methods

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.