#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int a[10] = {30, 20, 10 , 25 ,15,28} ;
int sy[10];// sy : {2,4,1,3,5,0};
int main() {
int n =6;
for(int i=0; i<n; i++) sy[i] = i;
//插入排序+索引排序
for(int i=1; i<n; i++){
//int vip = a[i] ;
int j = i-1;
while(j>=0 && a[sy[j]] > a[i]){ //a[j] > key
// a[j+1] = a[j];
sy[j+1] = sy[j];
j--;
}
// a[j+1] = key;
sy[j+1] = i;
}
for(int i=0; i<n; i++){
cout << a[i] << " ";
}
cout << endl ;
for(int i=0; i<n; i++){
cout << a[sy[i]] << " " ;
}
return 0;
}
—— 本文来自火龙信奥(义乌睿码科技):义乌青少年信息学奥赛与编程教育平台,专注 CSP-J/S、NOIP、GESP 竞赛培训,线上线下融合教学,助力编程升学。网址:hlcoding.com