冒泡排序
import java.util.Arrays;
public class Main {
public static void main(String []args)
{
int []a={3,1,6,0,-8,6,3,5,9,4};
MaoPao(a);
System.out.println(Arrays.toString(a));
}
public static int[] MaoPao(int []a)
{
int j=a.length-1;
int temp;
while(j>0)
{
for(int i=0;i<j;i++)
{
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
j--;
}
return a;
}
}
public class Main {
public static void main(String []args)
{
int []a={3,1,6,0,-8,6,3,5,9,4};
MaoPao(a);
System.out.println(Arrays.toString(a));
}
public static int[] MaoPao(int []a)
{
int j=a.length-1;
int temp;
while(j>0)
{
for(int i=0;i<j;i++)
{
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
j--;
}
return a;
}
}
本文来自博客园,作者:赵千万,转载请注明原文链接:https://www.cnblogs.com/zhaoqianwan/p/17891569.html
千万千万赵千万