码迷,mamicode.com
首页 > 编程语言 > 详细

冒泡排序

时间:2015-06-20 13:03:08      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

冒泡排序

技术分享
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace 冒泡排序
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             int[] oldArray = { 23, 44, 66, 76, 98, 11, 3, 9, 7 };
14             Console.Write("原始数组:");
15             foreach (var item in oldArray)
16             {
17                 Console.Write(item + " ");
18             }
19             PrintArray(oldArray);
20 
21             Console.ReadKey();
22         }
23         public static void PrintArray(int[] array)
24         {
25             int temp = 0;
26             for (int i = 0; i < array.Length; i++)
27             {
28                 for (int j = 0; j < array.Length - 1 - i; j++)
29                 {
30                     if (array[j] > array[j + 1])
31                     {
32                         temp = array[j];
33                         array[j] = array[j + 1];
34                         array[j + 1] = temp;
35                     }
36                 };
37                 Console.WriteLine();
38                 Console.WriteLine();
39                 Console.Write(""+(i+1)+"次排序后的结果:");
40                 foreach (var item in array)
41                 {
42                     Console.Write(item + " ");
43                 }
44             }
45         }
46     }
47 }
View Code

 

冒泡排序

标签:

原文地址:http://www.cnblogs.com/hghrpg/p/4590423.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!