1 using System;
 2 
 3 namespace ConsoleApp1
 4 {
 5     class Program
 6     {
 7         static int[] SelectArray(int[] bornArray) 
 8         {
 9             for (int i = 0; i < bornArray.Length; i++)
10             {
11                 int min = i;    //记录最小值的索引
12                 for (int j = i+1;j <bornArray.Length;j++)
13                 {
14                     if (bornArray[j] < bornArray[min])      //找出最小值并记录索引
15                     {
16                         min = j;
17                     }
18                 }
19                 int temp = bornArray[i];
20                 bornArray[i] = bornArray[min];
21                 bornArray[min] = temp;
22             }
23             return bornArray;
24         }
25         static void Main(string[] args)
26         {
27             int[] arrayInt = new int[] { 62,9,55,7,15,33};
28             Console.WriteLine("原数组为:");
29             foreach (int i in arrayInt)
30             {
31                 Console.Write(i + " ");
32             }
33             Console.WriteLine();
34             arrayInt = SelectArray(arrayInt);
35             Console.WriteLine("选择排序后:");
36             foreach (int i in arrayInt)
37             {
38                 Console.Write(i + " ");
39             }
40             Console.WriteLine();
41         }
42     }
43 } 

 

posted on 2020-06-08 21:06  kyuusan  阅读(289)  评论(0)    收藏  举报