1 using System; 2 3 namespace ConsoleApp1 4 { 5 class Program 6 { 7 static int[] MaoPaoArray(int[] bornArray) 8 { 9 for (int i = bornArray.Length; i > 0; i--) 10 { 11 for (int j = 0; j < i-1; j++) 12 { 13 if (bornArray[j+1] < bornArray[j]) 14 { 15 int temp = bornArray[j]; 16 bornArray[j] = bornArray[j + 1]; 17 bornArray[j + 1] = temp; 18 } 19 } 20 } 21 return bornArray; 22 } 23 static void Main(string[] args) 24 { 25 int[] arrayInt = new int[] { 62,9,55,7,15,33}; 26 Console.WriteLine("原数组为:"); 27 foreach (int i in arrayInt) 28 { 29 Console.Write(i + " "); 30 } 31 Console.WriteLine(); 32 arrayInt = MaoPaoArray(arrayInt); 33 Console.WriteLine("冒泡排序后:"); 34 foreach (int i in arrayInt) 35 { 36 Console.Write(i + " "); 37 } 38 Console.WriteLine(); 39 } 40 } 41 }
浙公网安备 33010602011771号