public static void BubbleSort<T>(T[] array) where T : IComparable
{
int n = array.Length;
for (int i = 0; i < n; i++)
{
for (int j = 1; j < n - i; j++)
{
if (array[j - 1].CompareTo(array[j])>0)
{
swap(ref array[j - 1], ref array[j]);
}
}
}
}
public static void swap<T>(ref T a, ref T b) where T : IComparable
{
T temp = a;
a = b;
b = temp;
}
算法复习--冒泡排序
最新推荐文章于 2024-07-11 21:13:07 发布