C#實現的從小到大的冒泡排序: public void BubbleSort(int[] array) { int length = array.Length; for (int i = 0; i < length - 1; i++) { for (int j = length - 1; j > i ...
C#實現的從小到大的冒泡排序:
public void BubbleSort(int[] array) { int length = array.Length; for (int i = 0; i < length - 1; i++) { for (int j = length - 1; j > i; j--) { // 對兩個元素進行交換 if (array[j] < array[j - 1]) { int temp = array[j]; array[j] = array[j - 1]; array[j - 1] = temp; } } } }