冒泡排序 J#
交换排序法-----冒泡排序 整体思路(已两两交换) 先找出数组中最大(小)的元素放在其位置
*/
static void BubbleSort(int[] sqList, boolean is_smallTbig) {
int sentinel = 0;
int i = sqList.length, j = 0;
if (is_smallTbig) {
for (boolean change = true; i > 0 && change; i--) {
change = false;// 如何已经有序则不用拍
for (j = 1; j < i; j++) {
sentinel = sqList[j];
if (sentinel < sqList[j - 1]) {
change = true;
sqList[j] = sqList[j - 1];
sqList[j - 1] = sentinel;
}
}
}
} else {
for (boolean change = true; i > 0 && change; i--) {
change = false;// 如何已经有序则不用拍
for (j = 1; j < i; j++) {
sentinel = sqList[j];
if (sentinel > sqList[j - 1]) {
sqList[j] = sqList[j - 1];
sqList[j - 1] = sentinel;
change = true;
}
}
}
}
}
上一篇: Spring Data JPA 使用感受
下一篇: Useful English idiom