/**
* 用冒泡排序,按升序给数组排序
* @param nums
*/
public static void bubble(int nums[]) {
int temp;
for (int i = 0; i < nums.length; i++) {
temp = nums[i];
for (int j = i + 1; j < nums.length; j++) {
if(temp > nums[j]) {
temp = nums[j];
nums[j] = nums[i];
nums[i] = temp;
}
}
}
}
public static void main(String[] args) {
System.out.println("冒泡排序法:");
int arr[] = {9,8,7,6,5,4,3,2,1};
LCContPolBL.bubble(arr);
for (int k = 0; k < arr.length; k++) {
System.out.print(arr[k] + ",");
}
}
04-07
11万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交