//数组排序,泛型约束写法
public static void sort<T>(T[] list) where T : System.IComparable<T>
{
T currentMin;
int currentMinIndex;
for (int i = 0; i < list.Length; i++)
{
currentMin = list[i];
currentMinIndex = i;
for (int j = i + 1; j < list.Length; j++)
{
if (currentMin.CompareTo(list[j]) > 0)
{
currentMin = list[j];
currentMinIndex = j;
}
}
if (currentMinIndex != i)
{
list[currentMinIndex] = list[i];
list[i] = currentMin;
}
}
}
public static void sort<T>(T[] list) where T : System.IComparable<T>
{
T currentMin;
int currentMinIndex;
for (int i = 0; i < list.Length; i++)
{
currentMin = list[i];
currentMinIndex = i;
for (int j = i + 1; j < list.Length; j++)
{
if (currentMin.CompareTo(list[j]) > 0)
{
currentMin = list[j];
currentMinIndex = j;
}
}
if (currentMinIndex != i)
{
list[currentMinIndex] = list[i];
list[i] = currentMin;
}
}
}