C#冒泡排序程序 发布时间:2023/10/11 冒泡排序 编程学习网为您整理以下代码实例,主要实现:C#冒泡排序程序,希望可以帮到各位朋友。 using System; namespace BubbleSort { class MySort { static voID Main(string[] args) { int[] arr = { 78, 55, 45, 98, 13 }; int temp; for (int j = 0; j <= arr.Length - 2; j++) { for (int i = 0; i <= arr.Length - 2; i++) { if (arr[i] > arr[i + 1]) { temp= arr[i + 1]; arr[i + 1] = arr[i]; arr[i] = temp; } } } Console.Writeline("Sorted:"); foreach (int p in arr) Console.Write(p + " "); Console.Read(); } } } 复制代码