#include <iostream> using namespace std; int arrSort[6]={5,2,4,6,1,3}; void insert_sort_asc(int arr[],int arrCount) { int key; int j; for(int i=1;i<arrCount;i++){ key=arr[i]; j=i-1; while(j>=0 && (arr[j]>key) ){ arr[j+1]=arr[j]; j--; }//while arr[j+1]=key; } //for } int main() { insert_sort_asc(arrSort,6); cout<<"\nAfter sorted....\n"; for(int i=0;i<6;i++){ std::cout<<arrSort[i]<<" "; } return 0; }
After sorted.... 1 2 3 4 5 6
參考:《算法导论》