【发布时间】:2015-06-08 07:47:38
【问题描述】:
void BubbleSort(int a[], int array_size) {
int i, j, temp;
for (i = 0; i < (array_size - 1); ++i) {
for (j = 0; j < array_size - 1 - i; ++j) {
if (a[j] > a[j+1]) {
temp = a[j+1];
a[j+1] = a[j];
a[j] = temp;
}
}
}
}
对于冒泡排序算法,为什么我们从第 1 个元素而不是第 0 个元素开始。正如我们所见,有 (++i) 和 (++j)。 这是唯一的,但我似乎无法在代码中掌握。
【问题讨论】:
-
你应该正确缩进你的代码,它会帮助你更快地理解发生了什么。
-
我认为 Google 会更好地解释。
-
why do we start with the 1st element and not the 0th element....你确定吗?
标签: c algorithm bubble-sort