/ *------------------------------------The basic idea of the sort of bubbling method------------------------------------
* 1: The value of the first element of the array inttest[0] is compared with the remaining elements, the maximum value is exchanged with inttest[0], and then the remaining elements are compared in turn
, you can get an array of sorts from large to small. As a result, the array length is n, at least the calculation steps to pass f (n): F (n) =f (n-1) + (n-1). Among them n>=1,f (1) =0
*/
1 namespacetestappliacion2 {3 class Program4 {5 Static voidMain (string[] args)6 {7 int[] inttest=New int[]{2,5,7, $,1};8 9 Testmath (inttest);Ten Console.readkey (); One } A // - Static voidTestmath (int[] inttest) - { the //before sorting - stringStrbefore =NULL; - foreach(intAinchinttest) - { +Strbefore + = a.tostring () +" "; - } +Console.WriteLine ("before sorting:"+strbefore); A //Bubble Method Sort at intn =0;//Sort Total Steps - for(inti =0; I < inttest.length-1; i++) - { - for(intj =1+i; J < Inttest.length; J + +) - { - if(Inttest[i] <Inttest[j]) in { - inttemp =Inttest[i]; toInttest[i] =Inttest[j]; +INTTEST[J] =temp; - } then++; * } $ }Panax Notoginseng //after sorting - stringStrafter =NULL; the foreach(intAinchinttest) + { AStrafter + = a.tostring () +" "; the } +Console.WriteLine ("after sorting:"+strafter); -Console.WriteLine ("Bubble sort requires {0} Order", n); $ } $ } -}
Bubble Method Sort