C#listsort底层原理
如果提供⽐较,则使⽤委托表⽰的⽅法对列表中的元素进⾏排序。如果comparison为null,则抛出ArgumentNullException。
此⽅法使⽤数组.排序,其应⽤⾃省排序,如下所⽰:
如果分区⼤⼩⼩于或等于16个元素,则使⽤插⼊排序算法
如果分区数超过2logn,其中n是输⼊数组的范围,则使⽤Heapsort算法。
否则,它将使⽤快速排序算法。
这个实现执⾏不稳定的排序;也就是说,如果两个元素相等,它们的顺序可能不会被保留。相反,稳定排序保留相等元素的顺序。
此⽅法是⼀个O(n logn)操作,其中n是Count。
官⽹⽂档:
Remarks
If comparison is provided, the elements of the  are sorted using the method represented by the delegate.
If comparison is null, an  is thrown.
This method uses , which applies the introspective sort as follows:
If the partition size is less than or equal to 16 elements, it uses an insertion sort algorithmsortedlist
If the number of partitions exceeds 2 log n, where n is the range of the input array, it uses a  algorithm.
Otherwise, it uses a Quicksort algorithm.
This implementation performs an unstable sort; that is, if two elements are equal, their order might not be preserved. In contrast, a stable sort preserves the order of elements that are equal.
This method is an O(n log n) operation, where n is .

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。