四、 简单排序之冒泡排序

原理如图所示(画图太丑将就看看):


源代码:

public class Bubblesort {
public static void bubblesort(int[] array) //冒泡排序
{
int temp; //存放中间数值
for(int i=0;i<array.length-1;i++) //一趟又一趟
{
for(int j=array.length-1;j>i;j--) //一个数往上冒冒冒
{
if(array[j]<array[j-1])
{
temp =array[j-1];
array[j-1] = array[j];
array[j] = temp;
}
}
}

}
}

原文地址:https://www.cnblogs.com/fyz666/p/8453831.html