首页 > 编程语言 > 详细

八大排序算法之 二 选择排序---冒泡排序算法

时间:2015-03-23 00:17:00      阅读:285      评论:0      收藏:0      [点我收藏+]

123

 

package primary;

public class BubbleSort {
    public static void main(String[] args){
         int[] array = {2,6,1,9,4,3,23,65,0,7};
         System.out.print("the array before is:");
         for(int i = 0; i < array.length; i++){
             System.out.print(array[i]+"  ");
         }
         System.out.println(" ");
         System.out.print("the array after is:");
         bubbleSort(array);
    }
    static void bubbleSort(int[] array){
        int len = array.length;
        for(int i = 0; i < len; i++){
            for(int j = 1; j < len - i; j++){
                if(array[j-1] > array[j]){
                    int temp = array[j-1];
                    array[j-1] =array[j];
                    array[j] = temp;
                }
            }
        }
        for(int z = 0; z < len; z++){
            System.out.print(array[z]+" ");
        }
    }
}

 

八大排序算法之 二 选择排序---冒泡排序算法

原文:http://www.cnblogs.com/RunForLove/p/4358338.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!