冒泡排序

 

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;
}
}
posted @ 2024-02-15 21:50  赵千万  阅读(3)  评论(0编辑  收藏  举报