Thursday, July 26, 2007

ShellSort

************************************************
c
The Shell Sort (Easy Trace Version)
Azhar Tazbirul 2007.07.26
************************************************
#include

main()
{
int data[]={58,12,39,90,49,26,68,47,15,39};

int i,j,gap,current,N,counter=0,show;
N =10;
for(i=0; i<10; i++) printf("%d ",data[i]);
printf("\n");
for(gap=N/2 ; gap >0 ; gap=gap/2){
for(i=gap;i current=data[i];
for(j=i;j>=gap && data[j-gap]>current;j=j-gap){
data[j]=data[j-gap];
for(show=0; show<10; show++) printf("%d ",data[show]);
printf("current=%d gap= %d \n",current,gap);
counter++;
}
data[j]=current;
}
}
printf("counter=%d\n",counter);
for(show=0; show<10;show++) printf("%d ",data[show]);
}

No comments:

Search