标签:
1 #include <iostream> 2 #include <iterator> 3 using namespace std; 4 5 void displayArray(int* const,int&); 6 7 void INSERTION_SORT(int * const A,int &length){ 8 int key; 9 int i; 10 for (int j = 1; j < length; ++j){ 11 key = A[j]; 12 i = j - 1; 13 while (i>=0 && key < A[i]){ 14 A[i + 1] = A[i]; 15 --i; 16 } 17 A[i + 1] = key; 18 } 19 displayArray(A, length); 20 } 21 22 void displayArray(int * const a,int &length){ 23 for (int i = 0; i < length; ++i){ 24 cout << " " << a[i]; 25 } 26 cout << endl; 27 } 28 29 int main(void) 30 { 31 int a[] = {5,2,4,6,1,3}; 32 int length = end(a) - begin(a); 33 INSERTION_SORT(a, length); 34 system("pause"); 35 return 0; 36 }
标签:
原文地址:http://www.cnblogs.com/lhyz/p/4305406.html