选择排序

 1 #include<iostream>
 2 using namespace std;
 3 //选择排序
 4 void select_sort(int a[], int n)
 5 {
 6     int i, j, m,t;
 7     for (i = 0; i < n-1; i++)
 8     {
 9         m = i;
10         for (j = i + 1; j < n; j++)
11         {
12             if (a[m]>a[j])
13                 m = j;
14         }
15         if (m != i)
16         {
17             t = a[i];
18             a[i] = a[m];
19             a[m] = t;
20         }
21         
22     }
23 }
24 int main()
25 {
26     int a[10];
27     for (int i = 0; i < 10; i++)
28         cin >> a[i];
29     for (auto t : a)
30         cout << t << " ";
31     cout << endl;
32     select_sort(a, 10);// 选择排序
33     for (auto t : a)
34         cout << t << " ";
35     cout << endl;
36     
37     system("pause");
38     return 0;
39 }
原文地址:https://www.cnblogs.com/wujufengyun/p/6826027.html