C#冒泡排序小试

 1  int[] PaoPAo = new int[10] { 88, 56, 91, 55, 74, 6, 35, 58, 45, 32 };
 2             for (int i = 0; i < PaoPAo.Length-1; i++)
 3             {
 4                 for (int j = 0; j < PaoPAo.Length-1-i; j++)
 5                 {
 6 
 7                   if (PaoPAo[j]>PaoPAo[j+1])
 8                        {
 9                             int temp=PaoPAo[j];
10                             PaoPAo[j] = PaoPAo[j + 1];
11                             PaoPAo[j + 1] = temp;   
12                           }
13                     foreach (int  x in PaoPAo)
14             {
15                 Console.Write(x+" ");
16             }
17                     Console.WriteLine("比较{0}次的结果:", j + 1);
18                 }
19 
20                 Console.WriteLine("第{0}次确定最大值",i+1);
21                 foreach (int x in PaoPAo)
22                 {
23                     Console.Write(x + " ");
24                 }
25                 Console.WriteLine(""); 
26             }
27 
28             Console.WriteLine();
29             foreach (int  x in PaoPAo)
30             {
31                 Console.Write(x+" ");
32             }
33            

 

参考一下运行结果,你估计就会慢慢了解了

posted on 2016-05-31 20:57  诗和远方的田野  阅读(233)  评论(0编辑  收藏  举报

导航