Java使用选择排序法对数组进行排序

 1 package com.yzy.test;
 2 
 3 public class Test {
 4 
 5     /**
 6      * @param args
 7      */
 8     public static void main(String[] args) {
 9         int[] array = { 43, 64, 21, 6565, 3424, 22, 6523, 345 };
10         for (int i = 1; i < array.length; i++) {
11             int index = 0;
12             for (int j = 1; j <= array.length - i; j++) {
13                 if (array[j] > array[index]) {
14                     index = j;
15                 }
16             }
17             int temp = array[array.length - i];
18             array[array.length - i] = array[index];
19             array[index] = temp;
20 
21         }
22         for (int i : array) {
23             System.out.print(i + " ");
24 
25         }
26     }
27 }

技术要点:每一趟从待排序的数据元素中选出最小(或最大)的一个元素,顺序放在已排好序的数列的最后,直到全部待排序的数据元素排完。

原文地址:https://www.cnblogs.com/yzyqqhr/p/5767645.html