首页 > 编程语言 > 详细

冒泡排序

时间:2019-12-23 17:14:02      阅读:95      评论:0      收藏:0      [点我收藏+]
/**
 * @Description:?【】?->冒泡排序
 * @Param: 
 * @Return: 
 * @Author: Mr.li
 * @Date: 2019/12/23
 */
public class DubbleSort {
    public static void main(String[] args) {
        int[] numbers = new int[]{1, 5, 8, 2, 3, 9, 4};
        int i, j;
        for (i = 0; i < numbers.length; i++) {
            for (j = 0; j < numbers.length - i - 1; j++) {
                if (numbers[j] > numbers[j + 1]) {
                    int temp = numbers[j];
                    numbers[j] = numbers[j + 1];
                    numbers[j + 1] = temp;
                }
            }
        }
        System.out.println("从小到大排序后的结果是:");
        for (i = 0; i < numbers.length; i++) {
            System.out.print(numbers[i] + " ");
        }
    }
}

冒泡排序

原文:https://www.cnblogs.com/name-lizonglin/p/12084192.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!