插入排序通用
#include <iostream>
using namespace std;
//插入排序通用
int main(){
int a[] = { 9,8,1,4,2,3,0,6,7,5 };
int n=sizeof(a)/sizeof(a[0]);
for (int j = 0; j < n; j++) {
cout << a[j] << " ";
}
cout << endl;
for(int i=1;i<n;i++){
int value=a[i];
int index=i-1;
while(index>=0 && a[index]>value){
a[index+1]=a[index];
index--;
}
a[index+1]=value;
}
for (int j = 0; j < n; j++) {
cout << a[j] << " ";
}
cout << endl;
getchar();
return 0;
}