1 #include<iostream> 2 using namespace std; 3 4 5 void Insertion_Sort(int a[],int n) 6 { 7 if (n == 1) 8 exit(1); 9 for (int k = 1; k < n; k++) 10 { 11 int x = a[k]; 12 int j = k - 1; 13 while (j >= 0 && a[j] > x) 14 { 15 a[j + 1] = a[j]; 16 j--; 17 } 18 a[j + 1] = x; 19 } 20 } 21 22 23 void main() 24 { 25 int a[10]; 26 for (int i = 0; i < 10; i++) 27 a[i] = 10 - i; 28 int n=sizeof(a) / sizeof(int); 29 Insertion_Sort(a, n); 30 for (int i = 0; i < 10; i++) 31 cout << a[i] << endl; 32 }