package com.itbaizhan.test.sort;

import java.util.Arrays;

public class Bubble {


    public static void main(String[] args) {
        int [] a = {2,4,1,3,9,6,5,7,0,8};//要排序的

        int b = 1;
        int c = 2;

        swap(b,c);

        System.out.println(c+"");



        for (int i = 0 ; i<a.length;i++){
            boolean DeterMine = true;
            for(int j = 0;j<a.length - i - 1;j++){
                if (a[j]>a[j+1]){
                    int temp = 0;
                    temp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = temp;
                    swap(a[j],a[j+1]);
                    DeterMine = false;
                }
            }
            if(DeterMine){
                break;
            }
            System.out.println("第"+(i+1)+"次排序:"+ Arrays.toString(a));

        }

    }


    static void swap(int a, int b){
        int temp = 0;
        temp = a ;
        a = b;
        b = temp;
    }

}

我的swap方法为什么不起效果

相关课程:JAVA 全系列>第一阶段:JAVA 快速入门>数组和数据存储>动画观察排序_冒泡排序_优化冒泡

©2014-2023 百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备13018289号-12    营业执照    经营许可证:京B2-20212637