/* This program is about the insertsort,Binsertsort,shellinsertsort*/
#include<iostream>
#include<cstdlib>
using namespace std;
const int MAX=10;
void insertSort(int list[])
{//This is insetsort
int i,j;
for(i=2;i<=MAX;i++)
{
if(list[i]<list[i-1])
{list[0]=list[i];
list[i]=list[i-1];
for(j=i-2;list[j]>list[0];j--)
list[j+1]=list[j];
list[j+1]=list[0];
}//for
}//for
}//insertSort
void BinsertSort(int list[])
{ //This is the Binary insetSOrt.
int i,low,high,mid,j;
for(i=2;i<=MAX;i++)
{ list[0]=list[i];
low=1;
high=i-1;
while(low<=high)
{ mid=(low+high)/2;
if(list[0]<list[mid])
high=mid-1;
else
low=mid+1;
}//while
for(j=i-1;j>=high+1;j--)
list[j+1]=list[j];
list[high+1]=list[0];
}//for
} //BinsetSort
void shellInsert(int list[],int dk)
{
int i,j;
for(i=dk+1;i<=MAX;i++)
if(list[i]<list[i-dk])
{ list[0]=list[i];
for(j=i-dk;j>0&&(list[j]>list[0]);j-=dk)
list[j+dk]=list[j];
list[j+dk]=list[0];
}
}//shellInsert
void shellSort(int list[],int dlta[],int t)
{
for(int k=0;k<t;k++)
shellInsert(list,dlta[k]);
}//shellSOrt
int main(void)
{
int list[MAX+1],i,n,dlta[3]={4,3,1};
for(i=1;i<=MAX;i++)
cin >>list[i];
shellSort(list,dlta,3);
cout<<"\nThe insetSort resault is:\n";
for(i=1;i<=MAX;i++)
cout <<list[i];
system("pause");
return 0;
}
评论