#include <iostream> using namespace std; void InsertSort( int k[], int n ) { int i, j,temp; for( i=1; i < n;i++ ) { if( k[i] < k[i-1] ) { temp = k[i]; for( j=i-1; k[j] > temp;j-- ) //找位置并且向后推移 { k[j+1] = k[j]; } k[j+1] = temp; } } } int main() { int i ,a[10] = {5,2,6,0,3,9,1,7,4,8}; InsertSort(a,10); for( i=0; i < 10 ;i++ ) { cout << a[i]; } cout << endl; return 0; }