C#简单的选择排序

代码
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Collections;
 6 
 7 namespace Max
 8 {
 9     class Program
10     {
11         public static int[] arry = new int[]{2,4,1,5,12};
12         static void Main(string[] args)
13         {
14             int t;
15             int imax;
16             for (int i =0; i <=arry.Length-1;i++ )
17             {
18                 imax = i;
19                 for (int j = i + 1; j <arry.Length;j++ )
20                 {
21                     if (arry[j]>arry[imax])
22                     {
23                         imax = j;
24                     }
25                     t = arry[i];
26                     arry[i] = arry[imax];
27                     arry[imax] = t;
28                 }
29             }
30             Console.WriteLine("排序后的序列为:");
31             foreach (int val in arry)
32             {
33                 Console.WriteLine("{0}",val);
34             }
35         }
36 
37     }
38 }
39 

 

posted on 2010-01-06 10:39  晴天1848  阅读(73)  评论(0)    收藏  举报