#include<iostream> using namespace std; void insert_sort(int a[], int n); int main(){ int a[]={ 3,7,2,9,6,5,8,1,4}; insert_sort(a,9); return 0; } void insert_sort(int a[], int n) { int i, j, temp,low,high,m; for (i = 1; i < n; ++i) { temp = a[i]; low=0; high=i-1; while(low<=high){ m=(low + high)/2; if(temp<a[m]){ high = m-1; }else{ low = m+1; } } for(j=i-1;j>high;j--){ a[j+1]=a[j]; } a[high+1]=temp; }//for for (i = 0; i < n; ++i){ cout<<a[i]<<" "<<endl; } }//insert