SHELL SORT
#include <stdio.h>
int main()
{
int arr[5] = {3,1,5,7,9};
int i;
int j;
int k;
int t;
int a;
for(i=5/2;i>0;i = i/2)
{
for(j = i;j<5;j++)
{
for(k = j-i;k>=0;k = k-i)
{
if(arr[k+i] >= arr[k])break;
else
{
t = arr[k+i];
arr[k+i] = arr[k];
arr[k] = t;
}
}
}
}
for(a = 0;a < 5;a++)
{
printf("%d",arr[a]);
}
}
Komentar
Posting Komentar