Is the sorting algorithm used by .NET\'s Array.Sort() method a stable algorithm?
UPDATE: This code not stabilizing Array.Sort (ensure that the elements are always sorted in the same order):
public static class ComparisonExtensions
{
public static Comparison WithGetHashCode(this Comparison current)
{
return (x, y) =>
{
var result = current(x, y);
if (result == 0)
return x.GetHashCode() - y.GetHashCode();
return result;
};
}
}
Use:
Comparison comparison = (x, y) => x.BirthYear.CompareTo(y.BirthYear);
Array.Sort(unstable, comparison.WithGetHashCode());