优化的选择排序——SelectionSortSecond
2016-12-26 12:31
295 查看
package sort.com;
public class SelectionSortSecond {
/**
*优化的选择排序,减少了交换次数
*
*/
}
public class SelectionSortSecond {
/**
*优化的选择排序,减少了交换次数
*
*/
public static void main(String[] args) { int []a = {5,-7,0,12,63,23,12,-6,1,-25}; for (int i= 0; i< a.length-1; i++){ //定义一个动态的索引, int minIndex = i; for (int j = i + 1; j < a.length; j++){ if(a[minIndex] > a[j]){ minIndex = j; } } //利用if语句将最小的放在每次比较结束的了序列的最前面,也就时已经有序的序列的最后面 if( minIndex != i){ int temp = a[i]; a[i] = a[minIndex]; a[minIndex] = temp; } } //遍历并输出数组 for ( int v :a){ System.out.print(v + "\t"); } }
}
相关文章推荐
- 3. 选择排序—直接选择排序(Straight Selection Sort)
- 选择排序—简单选择排序(Simple Selection Sort)原理以及Java实现
- 八大排序算法之三选择排序—简单选择排序(Simple Selection Sort)
- 选择排序—简单选择排序(Simple Selection Sort)
- 直接选择排序(Straight Selection Sort)
- 数据结构 - 只需选择排序(simple selection sort) 详细说明 和 代码(C++)
- Selection sort 选择排序
- java实现选择排序(selection_sort)
- 笔试算法题(56):快速排序实现之非递归实现,最小k值选择(non-recursive version, Minimal Kth Selection of Quick Sort)
- 选择排序之树形选择排序(TreeSelectionSort)
- 选择排序—简单选择排序(Simple Selection Sort)
- 【内部排序】六:直接选择排序(Straight Selection Sort)详解与代码
- 二次排序Mapreduce --SecondSort<转>
- 层层优化的选择排序
- 【数据结构与算法】内部排序之二:冒泡排序和选择排序(改进优化,附完整源码)
- 选择排序实现及优化--python
- 百万数据排序:优化的选择排序(堆排序)
- 排序之简单选择排序(Simple Selection Sort)
- 优化的选择排序和折半查找法
- 内部排序之二:冒泡排序和选择排序(改进优化,附完整源码)