• 冒泡排序(升序)


     1 /**
     2  * @author: yekai  <br/>
     3  * Date: 2021/11/16:0:04  <br/>
     4  * Description:4 6 5 2 1 3 使用冒泡排序 顺序排列
     5  */
     6 public class Main {
     7     public static void main(String[] args) {
     8         int[] a = { 4,6,5,2,1,3};
     9         int[] b = new int[6];
    10         b = sort(a);
    11         //输出
    12         for (int i = 0; i < b.length; i++) {
    13             System.out.print(b[i] + " ");
    14         }
    15 
    16     }
    17 
    18     //冒泡排序算法
    19     private static int[] sort(int[] a) {
    20 
    21         for (int i = 0; i < a.length; i++) {
    22 
    23             for (int j = 0; j < a.length-i-1; j++) {
    24                 //如果大于就互换
    25                 if(a[j]>a[j+1]){
    26                     int temp = a[j];
    27                     a[j] = a[j+1];
    28                     a[j+1] = temp;
    29                 }
    30             }
    31         }
    32         return a;
    33     }
    34 
    35 }
  • 相关阅读:
    微信小程序入门
    webpack
    模块化开发(1)
    HTML5表单
    移动端入门
    MySQL
    js面向对象与PHP面向对象总结
    PHP
    Git指令
    Redux
  • 原文地址:https://www.cnblogs.com/yekaiit/p/15560949.html
Copyright © 2020-2023  润新知