冒泡排序

/**
 * 
 * @author oyc
 *  冒泡排序
 */
public class bubble_sort {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int[] array=new int[10];
        //随即生成十个0-9的数,并把它输出
        System.out.print("排序前:");
        for(int i=0;i<10;i++){
            array[i]=(int)(Math.random()*10);
            System.out.print(array[i]+"   ");
        }
        
        for(int i=0;i<10;i++){
            for(int j=i;j<10;j++){
                if(array[i]>array[j]){
                    int temp=array[i];
                    array[i]=array[j];
                    array[j]=temp;
                    
                }
            }
        }
        //输出经过插入排序的数
        System.out.print("\n排序后:");
        for(int i=0;i<10;i++){
            System.out.print(array[i]+"   ");
        }
        
    }

}

posted @ 2016-01-09 09:45  乾源  阅读(128)  评论(0编辑  收藏  举报