博客
关于我
【算法】排序-冒泡排序 (java实现)
阅读量:541 次
发布时间:2019-03-09

本文共 666 字,大约阅读时间需要 2 分钟。

package com.billkang.algorithm.sort;import java.util.Arrays;/** * 冒泡排序 * * @author Kangbin * @date 2018-11-29 */public class BubbleSort {    public void bubbleSort(int[] arr) {        for (int i = 1; i < arr.length; i++) {            for (int j = 0; j < arr.length - i; j++) {                if (arr[j] > arr[j + 1]) {                    int temp = arr[j];                    arr[j] = arr[j + 1];                    arr[j + 1] = temp;                }            }        }    }    public static void main(String[] args) {        int[] arr = {9, 8, 7, 6, 5, 4, 3, 2, 1};        new BubbleSort().bubbleSort(arr);        System.out.println(Arrays.toString(arr));    }}

 

转载地址:http://dfeiz.baihongyu.com/

你可能感兴趣的文章
mysql的密码管理、mysql初始密码查找、密码修改、mysql登录
查看>>
mysql的常见八股文面试题
查看>>
MySQL的常见命令
查看>>
mysql的引擎以及优缺点_MySQL有哪些存储引擎,各自的优缺点,应用场景-阿里云开发者社区...
查看>>
MySQL的操作:
查看>>
mysql的数据类型有哪些?
查看>>