// 冒泡排序
public static void BubbleSort<T, C>(T[] array, C comparer)
where C : IComparer<T>
{
int length = array.Length;
for (int i = 0; i <= length - 2; i++) {
//Console.Write("{0}: ", i + 1);
for (int j = length - 1; j >= 1; j--) {
if (comparer.Compare(array[j], array[j - 1]) < 0) {
swap(ref array[j], ref array[j - 1]);
}
}
//Console.WriteLine();
//AlgorithmHelper.PrintArray(array);
}
}
C#排序算法一 冒泡排序
最新推荐文章于 2022-04-23 12:58:38 发布