冒泡排序

排序

public class BubbleSort {


public static void bubbleSort(){

int arg[] = {1,10,3,5,7,3,6};

int temp=0;

for(int i=0;i<arg.length-1;i++){

for(int j=0;j<arg.length-i-1;j++){ //控制区间

if(arg[j]<arg[j+1]){  //把最小的放到最后

temp = arg[j+1];

arg[j+1] = arg[j];

arg[j] = temp;

}

}

}

for(int n=0;n<arg.length;n++){

System.out.println(arg[n]);

}

}

public static void main(String[] args) {

// TODO Auto-generated method stub

       bubbleSort();

}


}


你可能感兴趣的:(冒泡排序)