冒泡排序

时间:2018-08-07 01:11:22   收藏:0   阅读:186

冒泡排序:

  

package com.review.algorithm;

public class BubbleSort {
    public static void main(String[] args) {
        String str = "4,3,2,6,7,1,5";

        String[] strs = str.split(",");

        String temp = "";

        for (int i = 0; i < strs.length; i++) {

            for (int j = i + 1; j < strs.length; j++) {

                if (Integer.parseInt(strs[i]) < Integer.parseInt(strs[j])) {

                    temp = strs[i];

                    strs[i] = strs[j];

                    strs[j] = temp;

                }

            }

        }

        for (int i = 0; i < strs.length; i++) {
            System.out.println(strs[i]);
        }

    }
}

  

原文:https://www.cnblogs.com/kongnengjing/p/9434307.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!