JAVA冒泡排序


/*
    冒泡排序算法:
        
        int类型的数组:3 1 6 2 5
        
*/
public class BubbleSort{
    
    public static void main(String[] args){
        
        int[] a ={3,1,6,2,5};
        
        //开始排序
        for(int i=a.length-1;i>0;i--){
            for(int j=0;ja[j+1]){
                    //交换位置
                    int temp;
                    temp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = temp;
                }
            }
        }
        
        //遍历
        for(int i=0;i

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