60分求助
查看原帖
60分求助
809643
dsy2022楼主2023/6/29 20:57
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000001;
int a[maxn];
void insertion_sort(int a[], int n){
	for(int i = 2; i <= n; i++){
		int key = a[i];
		int j = i-1;
		while(j >= 1 && a[j] > key){
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = key;
	}
}
int main(){
	int n;
	cin>>n;
	for(int i = 1; i <= n; i++) cin>>a[i];
	insertion_sort(a,n);
	for(int i = 1; i <= n; i++) cout<<a[i]<<" ";
	return 0;
}

成绩

2023/6/29 20:57
加载中...