Is the sorting algorithm used by .NET's `Array.Sort()` method a stable algorithm?

前端 未结 5 1118
灰色年华
灰色年华 2020-11-29 07:44

Is the sorting algorithm used by .NET\'s Array.Sort() method a stable algorithm?

5条回答
  •  清酒与你
    2020-11-29 08:37

    From MSDN:

    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.

    The sort uses introspective sort. (Quicksort in version 4.0 and earlier of the .NET framework).

    If you need a stable sort, you can use Enumerable.OrderBy.

提交回复
热议问题