选择排序
Posted Qunar_尤雪萍
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了选择排序相关的知识,希望对你有一定的参考价值。
选择排序
/**
* 选择排序
* Created by xueping.you on 15-8-5.
*/
public class ChooseSort
private final static Logger logger = LoggerFactory.getLogger(ChooseSort.class);
public static void chooseSort(int []unSortArray)
for(int i=0; i<unSortArray.length; i++)
int temp = unSortArray[i];
int smallestIndex = i;
for(int j=i+1; j<unSortArray.length;j++)
if(unSortArray[j]<temp)
smallestIndex=j;
temp=unSortArray[j];
if(smallestIndex!=i)
unSortArray[smallestIndex]=unSortArray[i];
unSortArray[i]=temp;
public static void main(String []args)
int [] array = new int[]12,10,2,45,31,56,1,9;
logger.info("before:", array);
chooseSort(array);
logger.info("after:",array);
result:
19:28:00.208 [main] INFO com.qyou.data.arithmetic.ChooseSort - before:[12, 10, 2, 45, 31, 56, 1, 9]
19:28:00.217 [main] INFO com.qyou.data.arithmetic.ChooseSort - after:[1, 2, 9, 10, 12, 31, 45, 56]
以上是关于选择排序的主要内容,如果未能解决你的问题,请参考以下文章