public static T[] SelectSort<T>(T[] orderArrary) where T: IComparable
{
if (orderArrary == null || orderArrary.Length == 0)
throw new Exception("Input arrary can not be Null or Empty.");
int minIndex;
T tempMin;
for (int i = 0; i < orderArrary.Length; i++)
{
//if (i == disorderArrary.Length - 1)
// continue;
minIndex = i;
for (int j = i + 1; j < orderArrary.Length; j++)
{
if (orderArrary[minIndex].CompareTo(orderArrary[j]) > 0)
{
minIndex = j;
}
}
tempMin = orderArrary[minIndex];
orderArrary[minIndex] = orderArrary[i];
orderArrary[i] = tempMin;
}
return orderArrary;
}
选择排序(Select Sort),如有问题,恳请指正。