zoukankan      html  css  js  c++  java
  • 选择排序

    选择排序:

    1. 从“待排序部分”中找到最小值
    2. 把最小值和“待排序部分起始位置的元素”交换
    3. “待排序部分”的起始位置向后移动一步
    4. 循环操作1~3,直至“待排序部分”只剩下一个元素


    public class Sort {
      public static void main(String[] args) {
      int[] a = new int[10];
      for (int i = 0; i < a.length; i++) {
        int b = (int) (Math.random() * 100);
        a[i] = b;
      }
      System.out.println("排序前:");
      for (int j = 0; j < a.length; j++) {
        System.out.print(a[j]+" ");
      }
      System.out.print(" ");
      selectSort(a);
      System.out.println("排序后:");
      for (int k = 0; k < a.length; k++) {
        System.out.print(a[k]+" ");
      }
    }

    public static int[] selectSort(int[] b){
      for(int i=0;i<b.length;i++){
        for(int j=i+1;j<b.length;j++){
          int temp;
          if(b[i]>b[j]){
            temp = b[i];
            b[i] = b[j];
            b[j] = temp;
          }
        }
      }
      return b;
      }
    }

  • 相关阅读:
    安装Docker-Compose
    Docker微容器Alpine Linux
    Linux 常用命令
    如何定制博客园的个人空间
    Elasticsearch入门之从零开始安装ik分词器
    Elasticsearch入门实践
    写在2017年的总结
    开源ETL工具之Kettle介绍
    常用Java数据库连接池
    细说shiro之七:缓存
  • 原文地址:https://www.cnblogs.com/kimyong/p/5896726.html
Copyright © 2011-2022 走看看