选择排序法

 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         /// <summary>
12         /// 排序算法有很多,包括插入排序,冒泡排序,堆排序,归并排序,选择排序,计数排序,基数排序,桶排序,快速排序等。插入排序,堆排序,选择排序,归并排序和快速排序,冒泡排序都是比较排序,它们通过对数组中的元素进行比较来实现排序,其他排序算法则是利用非比较的其他方法来获得有关输入数组的排序信息。
13         /// </summary>
14         /// <param name="args"></param>
15         static void Main(string[] args)
16         {
17             int[] nums = { 23, 23, 44, 66, 76, 98, 11, 3, 9, 7 };
18             int[] arr = Sort(nums);
19             foreach (int i in arr)
20             {
21                 Console.WriteLine(i.ToString());
22             }
23             Console.ReadKey();
24         }
25         /// <summary>
26         /// 选择排序,
27         /// </summary>
28         /// <param name="arr"></param>
29         /// <returns></returns>    
30         public static int[] Sort(int[] arr)
31         {
32             int min, temp;
33             for (int i = 0; i < arr.Length; i++)
34             {
35                 min = i;//初始化最小数序号为i
36                 for (int j = i ; j < arr.Length; j++)
37                 {
38                     if (arr[j] < arr[min])
39                     {
40                         min = j;//将最小数的序号存到min中,arr[min]就是最小数
41                     }
42                 }
43                 temp = arr[i];
44                 arr[i] = arr[min];
45                 arr[min] = temp;
46             }
47             return arr;
48         }               
49     }
50 }
原文地址:https://www.cnblogs.com/skyl/p/3782862.html