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