public class kaizi
{
public static void maopao(int arr[])
{
for(int i = 0;i < arr.length - 1;i++)
{
for(int j = 0;j < arr.length - i - 1;j++)
{
if(arr[j] > arr[j+1])
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
public static void main(String[] args)
{
int arr[] = {3,45,6,77,89,9,3,1};
printArray(arr);
maopao(arr);
printArray(arr);
}
public static void printArray(int arr[])
{
System.out.print("[");
for(int x = 0;x < arr.length;x++)
{
if(x != arr.length -1)
System.out.print(arr[x]+",");
else
System.out.println(arr[x]+"]");
}
}
}
java 1维数组冒泡法排序
最新推荐文章于 2023-11-13 21:55:34 发布