- 原题题目
- 代码实现
- 提交结果
原题题目
代码实现
#includeusing namespace std; int data[] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20}; int main() { int len = sizeof(data) / sizeof(int); for (int i = 1; i < len; ++i) { int insertnum = data[i]; int j = i; for (; j > 0; --j) { if (data[j - 1] > insertnum) { data[j] = data[j - 1]; } else { break; } } data[j] = insertnum; for (int k = 0; k < len; ++k) { if (k) cout << ' '; cout << data[k]; } cout << endl; } return 0; }
提交结果



