其他分享
首页 > 其他分享> > 冒泡排序

冒泡排序

作者:互联网


图解:



实例代码:

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;
}
}

标签:false,temp,arrays,冒泡排序,int,fal,public
来源: https://www.cnblogs.com/zsy3025/p/14797735.html