要依照 Tuple< string, ulong > 的 ulong 排序 List< Tuple< string, ulong > >
有蛇摸简洁又可以重复利用 Comparer 的写法ㄇ
目前写成这样
private static int CompareTupleSecondValue<T, V>(Tuple<T, V> v1, Tuple<T, V> v2)
{
return Comparer<V>.Default.Compare(v1.Item2, v2.Item2);
}
private static ulong GetMedian<T>(List<Tuple<T, ulong>> list)
{
list.Sort(CompareTupleSecondValue);
if (list.Count == 0)
return 0;
if (list.Count == 1)
return list[0].Item2;
if (list.Count % 2 == 1)
return list[list.Count / 2].Item2;
else
return (list[list.Count / 2 - 1].Item2
+ list[list.Count / 2].Item2) / 2;
}