[算法练习] 冒泡排序
2020-05-02 本文已影响0人
afluy
public void bubbleSort(int[] nums) {
if (nums == null) {
return;
}
if (nums.length == 1) {
return;
}
for (int times = 0; times < nums.length; ++times) {
int value = nums[0];
for (int index = 1; index < nums.length - times; ++index) {
int current = nums[index];
if (current < value) {
nums[index] = value;
nums[index - 1] = current;
}
value = nums[index];
}
}
for (int num : nums) {
System.out.println(num);
}
}