__夏_傷

导航

冒泡排序法

 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         }

 

posted on 2014-04-30 23:54  Pinson  阅读(152)  评论(0编辑  收藏  举报