/**
* 冒泡排序
* @params
* @author 奇
* @return
*/
public class Demo01 {
public static void main(String[] args) {
int[] nums = new int[]{23 , 4 , 5 , 24 , 13 , 65};
for (int i = 0; i < nums.length - 1; i++) {
for (int j = 0; j < nums.length - 1; j++) {
/*
* [0]>[1]
* 23>4
*/
if(nums[j] > nums[j+1]){
/*
* [0]=[0]+[1]
* 27=23+4
*/
nums[j] = nums[j] + nums[j+1];
/*
* [1]=[0]-[1]
* 23=27-4
*/
nums[j+1] = nums[j] - nums[j+1];
/*
* [0]=[0]-[1]
* 4=27-23
*/
nums[j] = nums[j] - nums[j+1];
/*
* 4 23 5 24 13 65
* 4 5 23 24 13 65
* 4 5 23 24 13 65
* 4 5 23 13 24 65
* 4 5 23 13 24 65
*/
}
}
}
for (int i = 0; i < nums.length; i++) {
System.out.print(nums[i] + "\t");
}
}
}