Which sorting algorithm is used by .NET's Array.Sort() method?

前端 未结 6 746
悲&欢浪女
悲&欢浪女 2021-02-12 15:44

Which sorting algorithm is used by .NET\'s Array.Sort() method?

6条回答
  •  佛祖请我去吃肉
    2021-02-12 15:48

    Array.Sort() chooses one of three sorting algorithm, depending on the size of the input:

    1. If the size is fewer than 16 elements, it uses an insertion sort algorithm.
    2. If the size exceeds 2 * log^N, where N is the range of the input array, it uses a Heap Sort algorithm.
    3. Otherwise, it uses a Quicksort algorithm

    Source: Array.Sort(Array) Method on MSDN.

提交回复
热议问题