首页 > 编程语言 > 详细

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

时间:2016-08-13 12:40:07      阅读:199      评论:0      收藏:0      [点我收藏+]
 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 }

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

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

原文:http://www.cnblogs.com/yzyqqhr/p/5767645.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!