Go 中的排序

  1. // A type, typically a collection, that satisfies sort.Interface can be
  2. // sorted by the routines in this package. The methods require that the
  3. // elements of the collection be enumerated by an integer index.
  4. type Interface interface {
  5. // Len is the number of elements in the collection.
  6. Len() int
  7. // Less reports whether the element with
  8. // index i should sort before the element with index j.
  9. Less(i, j int) bool
  10. // Swap swaps the elements with indexes i and j.
  11. Swap(i, j int)
  12. }

分类

十大基本排序算法的分类
image.png

复杂度

各排序算法复杂度对比

image.png
图片来自