冒泡排序


图解:
冒泡排序


实例代码:

package compary;

import java.util.Arrays;

public class Main {

public static void main(String[] args) {

int[] a={6,1,3,5,7,4,9};

int[] result=sort(a);

System.out.println(Arrays.toString(result)+",");
}

public static int[] sort(int[] arrays)
{
int temp=0;
boolean fal=false;
for (int i = 0; i <arrays.length-1 ; i++) {

for (int j = 0; j <arrays.length-1-i ; j++) {
if (arrays[j+1]>arrays[j])
{
temp=arrays[j];
arrays[j]=arrays[j+1];
arrays[j+1]=temp;
fal=true;
}
}
if (fal==false)
{
break;
}
}
return arrays;
}
}

上一篇:Contos7 常用命令(转)


下一篇:contos7中安装docker