这篇文章主要介绍了C#冒泡法排序算法,结合两个常用实例分析了C#冒泡排序算法的相关实现技巧,需要的朋友可以参考下
本文实例讲述了C#冒泡法排序算法。分享给大家供大家参考。具体实现方法如下:
static void BubbleSort(IComparable[] array) { int i, j; IComparable temp; for (i = array.Length - 1; i > 0; i--) { for (j = 0; j 0) { temp = array[j]; array[j] = array[j + 1]; array[j + 1] = temp; } } } }
泛型版本:
static void BubbleSort(IList list) where T : IComparable { for (int i = list.Count - 1; i > 0; i--) { for (int j = 0; j 0) { list[j] = next; list[j + 1] = current; } } } }
希望本文所述对大家的C#程序设计有所帮助。
以上就是C#冒泡法排序算法实例分析的详细内容,更多请关注0133技术站其它相关文章!