You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
638 B
23 lines
638 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int len = 10;
|
|
int a[] = {3, 5, 1, 7, 2, 4, 6, 9, 8, 0};
|
|
|
|
int main() {
|
|
//数组长度
|
|
int len = sizeof(a) / sizeof(int);
|
|
|
|
for (int i = 1; i < len; i++) {
|
|
int now = a[i]; //记录一下待插牌
|
|
int j = i - 1;
|
|
while (j >= 0 && a[j] > now) { //发现比待插入牌大
|
|
a[j + 1] = a[j]; //挪出位置
|
|
j--; //继续向前找
|
|
}
|
|
a[j + 1] = now; //放到合适的位置上
|
|
}
|
|
//输出
|
|
for (int i = 0; i < len; i++) printf("%d ", a[i]);
|
|
return 0;
|
|
} |