冒泡排序(java实现)

时间:2026-02-12 09:58:21

1、/**

 * 冒泡排序

 * @author zl

 *

 */

public class BubbleSort {

    public static void main(String[] args) {

        // TODO Auto-generated method stub

        int [] a = {1,-1,0,5,8};

        int temp;

        for(int i = a.length-1 ;i>0 ;i--){

            for(int j=0;j<i;j++){

                if(a[j+1]<a[j]){

                    temp = a[j+1];

                    a[j+1] = a[j];

                    a[j] = temp ;

                }

            }

        }

        System.out.println(Arrays.toString(a)); //将数组转换成字符串打印出来

    }

}

© 2026 一点资料
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com