冒泡排序 Java

来源:互联网 发布:逍遥游2.4软件下载 编辑:程序博客网 时间:2024/06/05 19:37

冒泡排序是最没有效率的排序,原因是 短视

/** * Created by fupeng on 2017/1/20. */public class bubble {    static void show(int [] a){        for(int i : a){            System.out.println(i);        }    }    static void exch(int [] a, int i, int j){        int t = a[i];        a[i] = a[j];        a[j] = t;    }    static void sort(int [] a){        for(int i=0 ; i<a.length -1 ; i++){            for(int j=0; j< a.length - i - 1; j++){                if(a[j+1] < a[j] )                    exch(a, j+1, j);            }        }    }    public static void main(String[] args) {        int [] a = {2,3,4,1,5,9,8,6,7,0};        sort(a);        show(a);    }}
0 0
原创粉丝点击