1.冒泡排序 請通過冒泡排序法對整數數組{ 1, 3, 5, 7, 90, 2, 4, 6, 8, 10 }實現升序排序 ...
1.冒泡排序
請通過冒泡排序法對整數數組{ 1, 3, 5, 7, 90, 2, 4, 6, 8, 10 }實現升序排序
int[] num = { 1, 3, 5, 7, 90, 2, 4, 6, 8, 10 }; BubbleSort(num); Console.ReadLine();
private static void BubbleSort(int[] num) { for (int i = 0; i < num.Length - 1; i++) { for (int j = num.Length - 1; j > i; j--) { if(num[j] < num[j - 1]) { int tmp = num[j]; num[j] = num[j - 1]; num[j - 1] = tmp; } } } for (int n = 0; n < num.Length; n++) { Console.WriteLine(num[n]); } }