C#————選擇結構
阿新 • • 發佈:2018-12-21
**選擇結構**
int[] num = new int[] {23,76,54,87,51,12 }; //氣泡排序 for (int i = 0; i < num.Length - 1; i++) { for (int j = 0; j < num.Length - 1 - i; j++) { if (num[j] > num[j + 1]) { int sum = num[j]; num[j] = num[j + 1]; num[j + 1] = sum; } } } //選擇排序 for (int i = 0; i < num.Length - 1; i++) { for (int j = i + 1; j < num.Length; j++) { if (num[i] > num[j]) { int num1 = num[i]; num[i] = num[j]; num[j] = num1; } } } for (int i = 0; i < num.Length;i++ ) { Console.WriteLine(num[i]); }