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