冒泡和选择排序 事例
class Program {
//冒泡排序 static void Main(string[] args) { int[] a = { 3, 7, 1, 2 }; for (int i = 3; i > 0; i--) { for (int j = 0; j < i; j++) { if (a[j] > a[j + 1]) { int stemp = a[j]; a[j] = a[j + 1]; a[j + 1] = stemp; } } } foreach(int i in a) { Console.Write(i.ToString()+" "); } Console.ReadLine(); } }
选择排序