|
#include <iostream> using namespace std; void InsertSort(int a[],int n) { int temp; int j; for(int i=1;i<n;i++) { if(a[i]<a[i-1]) { temp = a[i]; j = i-1; do { a[j+1] = a[j]; j--; }while(temp<a[j] && j>=0); } a[j+1] = temp; } } int main() { int r[14] = {10,2,12,3,4,89,5,45,21,7,90,112,78,91}; InsertSort(r,14); for(int i=0;i<14;i++) { cout<<r[i]<<endl; } getchar(); return 0; }
|