冒泡排序法

时间:2014-05-01 09:19:38   收藏:0   阅读:279
mamicode.com,码迷
 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         }
mamicode.com,码迷

 

冒泡排序法,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!