首页 > 代码库 > 冒泡排序法

冒泡排序法

 1         /// <summary>
 2         /// 冒泡排序法-for循环
 3         /// </summary>
 4         /// <param name="array"></param>
 5         private static void BubbleSort(int[] array)
 6         {
 7             var length = array.Length;
 8             for (int i = 0; i < length;i++ )
 9             {
10                 for (int j = length-1; j > i; j--)
11                 {
12                     if (array[j] < array[j - 1])
13                     {
14                         int temp = array[j];
15                         array[j] = array[j - 1];
16                         array[j - 1] = temp;
17                     }
18                 }
19             }
20         }