#include <iostream>
#include <iomanip>
using namespace std;
#define NUM 10
void HalfInsertSort(int list[],int n)
{
int low;
int high;
int mid;
int x;
int i;
int j;
for (i=1;i<n;i++)
{
x = list[i];
low = 0;
high = i-1;
while (low<=high)
{
mid = (low+high)/2;
if (x<list[mid])
{
high = mid-1;
}
else
{
low = mid+1;
}
}
for (j=i-1;j>=high+1;j--)
{
list[j+1] = list[j];
}
list[high+1] = x;
}
}
void Print(int r[],int n)
{
int i;
for (i=0;i<n;i++)
{
cout << setw(5) << r[i] << setw(5);
}
cout << endl;
}
int main()
{
int arr[NUM];
int i;
srand(1);
for (i=0;i<NUM;i++)
{
arr[i] = rand()%100;
}
cout << "before sorting " << endl;
Print(arr,sizeof(arr)/sizeof(int));
HalfInsertSort(arr,sizeof(arr)/sizeof(int));
cout << "after sorting " << endl;
Print(arr,sizeof(arr)/sizeof(int));
return 0;
}