这里使用的排序方式是冒泡
public class ArrayHelper
{
public static void Sort<T>(T[] array) where T : IComparable<T>
{
for (int i = 0; i < array.Length; i++)
for (int j = i + 1; j < array.Length; j++)
{
if (array[i].CompareTo(array[j]) > 0)
{
T tmp = array[i];
array[i] = array[j];
array[j] = tmp;
}
}
}
public static void Sort<T>(T[] array, IComparer<T> comparer)
{
for (int i = 0; i < array.Length; i++)
for (int j = i + 1; j < array.Length; j++)
{
if (comparer.Compare(array[i], array[j]) > 0)
{
T tmp = array[i];
array[i] = array[j];
array[j] = tmp;
}
}
}
public delegate int Comparison<T>(T a, T b);
public static void Sort<T>(T[] array, Comparison<T> comparison)
{
for (int i = 0; i < array.Length; i++)
for (int j = i + 1; j < array.Length; j++)
{
if (comparison(array[i], array[j]) > 0)
{
T tmp = array[i];
array[i] = array[j];
array[j] = tmp;
}
}
}
}