1 internal static int[] BubbleSortMethod(int[] inputArray)
2 {
3 for (int ensureCount = 0; ensureCount < inputArray.Length - 1; ensureCount++)
4 {
5 for (int compareIndex = 0; compareIndex < inputArray.Length - ensureCount - 1; compareIndex++)
6 {
7 if (inputArray[compareIndex] > inputArray[compareIndex + 1])
8 {
9 int temp = inputArray[compareIndex];
10 inputArray[compareIndex] = inputArray[compareIndex + 1];
11 inputArray[compareIndex + 1] = temp;
12 }
13 }
14 }
15 return inputArray;
16 }
冒泡算法是一种稳定的排序算法。
冒泡排序最好的时间复杂度是,最坏时间复杂度为
,平均时间复杂度为
。
原文:http://www.cnblogs.com/ByronsHome/p/3527033.html