15/08/13 21:42:16.81 uEvY/8an.net
>>441
なるほど……こんなん書いてみたけど、これってありですか?
それとも自前の安定なソートメソッドを書きますか?
public static void StableSort<T>( this IList<T> list )
{
var temp = list.OrderBy( t => t ).ToList(); // 既定の比較でソート
for( int i = 0; i < list.Count; i++ )
{
list[i] = temp[i];
}
}
その前はこんなん書いてみたてたけどw
public static void StableSort<T>( this IList<T> list )
{
var wrapper = list.Select( ( t, i ) => new KeyValuePair<int, T>( i, t ) ).ToList();
wrapper.Sort( ( p1, p2 ) =>
{
var result = Comparer<T>.Default.Compare( p1.Value, p2.Value );
if( result == 0 )
{
result = p1.Key.CompareTo( p2.Key );
}
return result;
} );
for( int i = 0; i < list.Count; i++ )
{
list[i] = wrapper[i].Value;
}
}