选择排序 C#
1.
1 class Program
2 {
3 static void Main(string[] args)
4 {
5 int[] iArrary = new int[] { 1, 5, 3, 6, 10, 55, 9, 2, 87, 12, 34, 75, 33, 47 };
6 SelectionSorter ss = new SelectionSorter();
7 ss.Sort(iArrary);
8 for (int m = 0; m < iArrary.Length; m++)
9 {
10 Console.Write("{0} ", iArrary[m]);
11 }
12 Console.ReadLine();
13 }
2 {
3 static void Main(string[] args)
4 {
5 int[] iArrary = new int[] { 1, 5, 3, 6, 10, 55, 9, 2, 87, 12, 34, 75, 33, 47 };
6 SelectionSorter ss = new SelectionSorter();
7 ss.Sort(iArrary);
8 for (int m = 0; m < iArrary.Length; m++)
9 {
10 Console.Write("{0} ", iArrary[m]);
11 }
12 Console.ReadLine();
13 }
14 }
2.选择排序
1 class SelectionSorter
2 {
3 private int min;
4 /// <summary>
5 /// 选择排序
6 /// </summary>
7 public void Sort(int[] list)
8 {
9 for (int i = 0; i < list.Length - 1; i++)
10 {
11 min = i;
12 for (int j = i + 1; j < list.Length; j++)
13 {
14 if (list[j] < list[min])
15 min = j;
16 }
17 int t = list[min];
18 list[min] = list[i];
19 list[i] = t;
20 }
21 }
2 {
3 private int min;
4 /// <summary>
5 /// 选择排序
6 /// </summary>
7 public void Sort(int[] list)
8 {
9 for (int i = 0; i < list.Length - 1; i++)
10 {
11 min = i;
12 for (int j = i + 1; j < list.Length; j++)
13 {
14 if (list[j] < list[min])
15 min = j;
16 }
17 int t = list[min];
18 list[min] = list[i];
19 list[i] = t;
20 }
21 }
22 }
乌龟才背着房子过一辈子