- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace SelectionSorter
- {
- /// <summary>
- /// 选择排序
- /// 作者:范中磊
- /// </summary>
- public class SelectionSorter
- {
- public void Sort(int[] list)
- {
- int min;
- for (int i = 0; i < list.Length - 1; i++)
- {
- min = i;
- for (int j = i + 1; j < list.Length; j++)
- {
- if (list[j] < list[min])
- min = j;
- }
- int temp = list[min];
- list[min] = list[i];
- list[i] = temp;
- }
- }
- public static void Main(string[] args)
- {
- int[] iarrary = new int[] { 1, 5, 3, 6, 10, 55, 9, 2, 87, 12, 34, 75, 33, 47 };
- SelectionSorter ss = new SelectionSorter();
- ss.Sort(iarrary);
- for (int m = 0; m < iarrary.Length; m++)
- Console.Write("{0} ", iarrary[m]);
- Console.WriteLine();
- Console.ReadLine();
- }
- }
- }
C# 选择排序
最新推荐文章于 2023-09-01 15:50:39 发布