Fork me on GitHub

冒泡排序

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         }

 

posted @ 2017-07-05 20:04  薄荷加冰2060  阅读(113)  评论(0编辑  收藏  举报