import java.util.Scanner;
public class 第六次冒泡排序 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.print("数组长度:");
int num = sc.nextInt();
int a[] = new int[num];
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
}
bubbleSort(a);
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]+" ");
}
}
public static void bubbleSort(int []a)
{
for(int i=0;i<a.length;i++)
{
for(int j=1;j<a.length;j++)
{
if(a[j]<a[j-1])
{
int temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
}
}
}
}
}
冒泡排序
最新推荐文章于 2022-04-29 23:24:15 发布