Is the sorting algorithm used by .NET's Array.Sort()
method a stable algorithm?
views:
2030answers:
4
+24
A:
From MSDN:
This method uses the 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.
Rasmus Faber
2008-09-29 09:24:31
A:
No, it isn't:
This method uses the QuickSort algorithm. This implementation performs an unstable sort
Konrad Rudolph
2008-09-29 09:24:38
+10
A:
As other answers have stated, Array.Sort isn't stable. However, the LINQ OrderBy methods (and OrderByDescending etc) are stable, which can be very useful.
Jon Skeet
2008-09-29 09:40:29