package ArrayDemo; public class BubbleArray { public static void main(String[] args) { int[] arr={2,5,1,3}; bubble(arr); for (int a:arr ) { System.out.println(a); } } public static void bubble(int[] arr){ for(int i=0;i<arr.length-1;i++){ for(int j=0;j<arr.length-i-1;j++){ int temp=0; if(arr[j]>arr[j+1]){ temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp; } } } } }
数组的冒泡排序
最新推荐文章于 2022-05-06 13:53:00 发布