C# -- 冒泡排序
1. C#代码
1 int[] num = { 3, 5, 7, 1, 2, 13, 9, 4, 6, 11, 22, 44, 33, 14, 43, 41, 5, 868, 476, 34535, 345, 46, 47, 47, 848 };
2 for (int i = 0; i < num.Length - 1; i++) 3 { 4 for (int j = num.Length - 1; j > i; j--) 5 { 6 if (num[j] < num[j - 1]) 7 { 8 int temp = num[j]; 9 num[j] = num[j - 1]; 10 num[j - 1] = temp; 11 } 12 } 13 } 14 Console.WriteLine("排序后的数组:"); 15 for (int k = 0; k < num.Length; k++) 16 { 17 Console.Write("{0},", num[k]); 18 } 19 20 Console.ReadKey();
2. 运行结果: