#include <iostream>
using namespace std;
int main() {
int n=7;
int a[7]= {8,3,5,1,2,9,0};
for(int i=1; i<n; i++) {
int temp=a[i];
int j;
for(j=i-1; j>=0&&temp<a[j]; j--)
a[j+1]=a[j];
a[j+1]=temp;
}
for(int i=0; i<7; i++) {
cout<<a[i]<<' ';
}
return 0;
}
插入排序算法实现
最新推荐文章于 2024-07-13 23:05:26 发布