sorting algorithm
  • Introduction
  • Wikipedia-sorting-algorithm
  • sorting algorithm
  • 历史 History
  • 分类 Classification
    • 稳定性 Stability
  • 算法比较 Comparison of algorithms
  • 流行排序算法 Popular sorting algorithms
    • 简单排序 Simple sorts
      • 插入排序 Insertion sort
      • 选择排序 Selection sort
    • 高效排序 Efficient sorts
      • 合并排序 Merge sort
      • 堆排序 Heapsort
      • 快速排序 Quicksort
    • 冒泡排序与变种 Bubble sort and variants
      • 冒泡排序 Bubble sort
      • 希尔排序 Shellsort
      • 梳排序 Comb sort
    • 分发排序 Distribution sort
      • 计数排序 Counting sort
      • 桶排序 Bucket sort
      • 基数排序 Radix sort
  • 内存使用模式和索引排序 Memory usage patterns and index sorting
  • 相关算法 Related algorithms
  • 另见 See also
  • 参考文献 References
  • 进一步阅读 Further reading
  • 外部链接 External links
Powered by GitBook
On this page
  • Selection sort选择排序
  • principle原理
  • example示例

Was this helpful?

  1. 流行排序算法 Popular sorting algorithms
  2. 简单排序 Simple sorts

选择排序 Selection sort

Previous插入排序 Insertion sortNext高效排序 Efficient sorts

Last updated 5 years ago

Was this helpful?

Selection sort选择排序

@See @See - SelectionSort

principle原理

从列表第一位开始向高位进行排序 向后查询,找到比当前值小的最小值与当前值置换 双for循环推进排序

example示例

public void sort(int[] list) {
        for(int i = 0; i<list.length-1; i++){
            int min = i;
            //find min
            for(int j = i+1; j<list.length ;j++){
                if(list[j] <list[min]){
                    min = j;
                }
            }
            //swap the min with the ith element
            swap(list, min, i);
        }
    }
https://en.wikipedia.org/wiki/Selection_sort
https://github.com/jiek2529/java_algorithm