首页 > 其他 > 详细

选择排序

时间:2014-08-23 18:54:11      阅读:283      评论:0      收藏:0      [点我收藏+]
 1 package com.learning.algorithm;
 2 
 3 public class SelectSort {
 4 
 5     public int[] selectSort(int[] arrValue){
 6         int temp = 0;
 7         int min;
 8         for(int i=0;i<arrValue.length-1;i++){
 9             min = i;
10             for(int j=i+1;j<arrValue.length;j++){
11                 if(arrValue[j]<arrValue[min]){
12                     min = j;
13                 }
14             }
15             temp = arrValue[i];
16             arrValue[i] = arrValue[min];
17             arrValue[min] = temp;
18         }
19         return arrValue;
20     }
21     
22     /**
23      * @param args
24      */
25     public static void main(String[] args) {
26         int[] arrValue = {89,39,56,93,2,58,43,51,33,67};
27         SelectSort ss = new SelectSort();
28         int[] arrResult = ss.selectSort(arrValue);
29         for(int value:arrResult){
30             System.out.print(value);
31             System.out.print(",");
32         }
33         
34 
35     }
36 
37 }

 

选择排序

原文:http://www.cnblogs.com/ryanwangblog/p/3931532.html

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