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);
}
}
网友评论