tags:

views:

2030

answers:

4

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

+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
A: 

No, it isn't:

This method uses the QuickSort algorithm. This implementation performs an unstable sort

Konrad Rudolph
+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
+20  A: 
Atif Aziz