直接插入排序
#include <iostream> using namespace std; void insort (int s[], int n) { for (int i = 2; i <= n; i++) { s[0] = s[i]; int j = i - 1; while (s[0] < s[j]) { s[j + 1] = s[j]; j--; } s[j + 1] = s[0]; } } int main() { int a[111]; for (int i = 1; i < 11; i++) cin >> a[i]; insort(a, 10); for (int i = 1; i < 11; i++) cout << a[i] << ' '; return 0; }