# 算法|冒泡排序

public class BubbleSort {
public static void main(String[] args) {
int[] nums = new int[]{1, 15, 3, 78, 34, 23, 46, 2, 8, 34, 57};
System.out.println("before insert sort "+ Arrays.toString(nums));
sort(nums);
System.out.println("after insert sort "+Arrays.toString(nums));

}

public static void sort(int[] arrays) {
int length = arrays.length;
for(int i=0; i< length; i++) {

for(int j = length -1; j>0; j--) {
if (arrays[j] < arrays[j - 1]) {
int temp = arrays[j];
arrays[j] = arrays[j-1];
arrays[j-1] = temp;
}

}

}

}
}

 public static void sort(int[] arrays) {
int length = arrays.length;
for(int i=0; i< length; i++) {

for(int j = length -1; j>i; j--) {
if (arrays[j] < arrays[j - 1]) {
int temp = arrays[j];
arrays[j] = arrays[j-1];
arrays[j-1] = temp;
}

}

}

}

 for(int j=i ; j> 0 && arrays[j] < arrays[j-1] ; j--) {

int temp = arrays[j];
arrays[j] = arrays[j - 1];
arrays[j-1] = temp;
}

 for (int j = length - 1; j > i && arrays[j] < arrays[j - 1]; j--) {
int temp = arrays[j];
arrays[j] = arrays[j - 1];
arrays[j - 1] = temp;

}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120