冒泡排序
1 package cn.itcast.demo2; 2 import java.util.Arrays; 3 public class MaoPao { 4 public static void main(String[] args) { 5 int arry[]={1,2,5,3}; 6 function(arry); 7 } 8 public static void function(int[] arry){ 9 10 //int t=0; 11 for(int i=0;i<arry.length;i++){ 12 for(int j=0;j<arry.length-i-1;j++){ 13 if(arry[j]>arry[j+1]){ 14 int t=arry[j]; 15 arry[j]=arry[j+1]; 16 arry[j+1]=t; 17 } 18 } 19 } 20 System.out.println(Arrays.toString(arry)); 21 } 22 }

浙公网安备 33010602011771号