冒泡排序

冒泡排序:

  

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]);
        }

    }
}

  

posted @ 2018-08-06 23:52  空能净  阅读(117)  评论(0编辑  收藏  举报