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

     1 public class Test3 {
     2 
     3     /**@author shaobn
     4      * @param 选择排序:将a.length - i个元素分别和第i个元素相比较,小的话就将值调换。依次递减进行排列
     5      */
     6     public static void main(String[] args) {
     7         // TODO Auto-generated method stub
     8         int[] a=  {20,23,11,13,35,34,657};
     9         Method1(a);
    10     }
    11     public static void Method1(int[] a){
    12         int temp;
    13         int value;
    14         for (int i = 0; i < a.length; i++) {
    15             temp = i;
    16             for (int j = i+1; j < a.length; j++) {
    17                 if(a[j]<a[temp]){
    18                     temp = j;
    19                 }
    20             }
    21             value = a[i];
    22             a[i] = a[temp];
    23             a[temp] = value;
    24             
    25         }
    26         for (int i = 0; i < a.length; i++) {
    27             System.out.println(a[i]);
    28         }
    29     }
    30 }
  • 相关阅读:
    PYTOHN1.day14
    PYTHON1.day13
    PYTHON1.day12
    PYTHON1.day11(n)
    PYTHON1.day10
    PYTHON1.day09
    PYTHON1.day08
    同步代码块 synchronized
    守护线程
    休眠线程
  • 原文地址:https://www.cnblogs.com/assassin666/p/4835112.html
Copyright © 2011-2022 走看看