• 数据结构与算法——简单排序


     冒泡排序

     从第一个开始,依次比较跟下一个的高度,高的放后面,最高的放后面;最高放在最后,然后再把剩下的再来排序一次

    public class BubbleSortMain{

    public static void main(String[] args){

    int[] arr = {3,43,38,5,47,36,26};
    bubbleSort(arr);

    }


    #冒泡排序
    private static void bubbleSort(int[] arr)
    {
    for(int i=0;i<arr.length;i++)
    for(int j=0;j<arr.length-i-1;j++){
    #这里说明为什么要-1
    #因为最大放后面,然后接着从第一个依次比较,长度递减
    if (arr[j] > arr[j + 1]) {

    int temp = arr[j];

    arr[j] = arr[j + 1];

    arr[j + 1] = temp;

    }


    }
    }


    }

    just move on
  • 相关阅读:
    502 bad gateway错误的网关
    nodejs发展
    edgejs
    websocket nodejs实例
    nodejs原码
    node案例
    node 与php整合
    node c#
    jquery
    express
  • 原文地址:https://www.cnblogs.com/ql70me/p/14884813.html
Copyright © 2020-2023  润新知