shellsort

#include <stdio.h>

void shellsort(int a[], int n, int delt)
{
	int i;
    
	for(i = delt; i+delt <= n; i ++)
    {
		int temp = a[i];
		int j = i - delt;

		while(temp < a[j])
		{
			a[j + delt] = a[j];
			j = j - delt;
		}

		a[j + delt] = temp;
	}
}

void mainsort(int a[], int n, int delt[], int r)
{
	int i;

    for(i = 0; i < r; i++)
	{
		shellsort(a, n, delt[i]);
	}
}

int main(void)
{
	int i;
	int a[4] = {5, 3, 6, 8};
	int delt[2] = {2, 1};

	mainsort(a, 4, delt, 2);
    for(i = 0; i < 4; i++)
		printf("%d  ", a[i]);
	
	printf("\n");
}

  

posted @ 2014-03-23 09:19  elroyzhang  阅读(330)  评论(0编辑  收藏  举报