首页 > 代码库 > 冒泡排序

冒泡排序

C#

 1  public static int[] BubbleSort(int[] array)
 2         {
 3             int length = array.Length;
 4             for(int i=0;i<length-1;i++)
 5             {
 6                 for (int j = 0; j < length - i - 1; j++)
 7                 { 
 8                     if (array[j] >array[j+1])
 9                     {
10                         int temp = array[j];
11                         array[j] = array[j+1];
12                         array[j+1] = temp;
13                     }
14                 }
15             }
16 
17             return array;
18         }

 

冒泡排序