排序-冒泡排序

排序-冒泡排序,第1张

排序-冒泡排序
public class Bubble {
    public static void sort(Comparable[] a){

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



    private static void exch(Comparable[] a,int i,int j){
        Comparable temp;
        temp=a[i];
        a[i]=a[j];
        a[j]=temp;
    }
}

//测试

import java.util.Arrays;

public class BubbleTest {

    public static void main(String[] args) {

       Integer[] arr={4,5,2,6,1,3};
       Bubble.sort(arr);

        System.out.println(Arrays.toString(arr));
    }
}

结果:

D:javajdkjdk-14.0.2binjava.exe "-javaagent:D:ideaIC-2021.2.2IDEAIntelliJ IDEA 2020.1.1libidea_rt.jar=50316:D:ideaIC-2021.2.2IDEAIntelliJ IDEA 2020.1.1bin" -Dfile.encoding=UTF-8 -classpath E:ideaProjectitcastoutproductiondata_structure BubbleTest
[1, 2, 3, 4, 5, 6]

Process finished with exit code 0
 

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5609324.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存