Exemplo n.º 1
0
void ShellSort(SqList *L,int dlta[])//希尔排序
{
    int k,j=L->len/2,t=0;
    int compare,change;
    while(j>=0)
    {
        ++t;
        j-=2;
    }
    j=L->len/2;
    for(k=0;k<t;++k)//计算每次的增量值
    {
        if(j==0)
            j=1;//定义最后一趟排序的增量
        dlta[k]=j;
        j-=2;
    }
    for(k=0;k<t;++k)
        ShellInsert(L,dlta[k]);
    printf("\n-----希尔排序后顺序-----\n");
    for(k=1;k<=L->len;k++)
        printf("%d  ",L->r[k].key);
    printf("\n");
    printf("希尔排序比较次数为:%d\n",compare);
    printf("希尔排序移动次数为:%d\n",change*3);
}
Exemplo n.º 2
0
//对记录r做希尔排序,length为数组r的长度
//delta为增量数组,n为delta[]的长度
void ShellSort(RecordType r[], int length)
{
    for(i=0; i<=n-1; ++i)
    {
	ShellInsert(r,length,delta[i]);
    }
}
Exemplo n.º 3
0
void ShellSort( SqList* l, int* d, int n )
{
	int i = 0;
	for( i = 0; i < n; i++)
	{
		ShellInsert( l, d[i] );
	}
}
Exemplo n.º 4
0
void ShellSort(SqList &L,int dlta[],int t,int &compare,int &move){// Ï£¶ûÅÅÐò
	int k;
	compare=move=0;
	for(k=0;k<t;++k)
	{
		ShellInsert(L,dlta[k],compare,move); 
	}
};
Exemplo n.º 5
0
void ShellSort(int array[], int len, int dlta[], int t)
{
    int i;
    for(i=0; i<t; i++)
    {
        ShellInsert(array, len, dlta[i]);
    }

    return;
}
Exemplo n.º 6
0
void ShellSort(int num[], int length)
{
    //步长选择为n/2并且对步长取半直到步长达到 1
    int delta = length/2;
    while(delta>0)//最后一次的步长为1
    {
        ShellInsert(num,length,delta);
        delta = delta/2;
    }
}
Exemplo n.º 7
0
void ShellSort(int R[],int n) 
{
   int i;
   for(i = n/2; i>0; i = i/2) //各趟插入排序
   ShellInsert(R,n,i); 
}
Exemplo n.º 8
0
void ShellSort(SqList &L,int dlta[],int t){
	//O(n1.3);不稳定
	for(int k=0;k<t;++k){
		ShellInsert(L,dlta[k]);
	}
}