http://forum.html.it/forum/showthrea...ight=shellsort
e questo è il programma completo:
codice:
#include <stdio.h>
#include <stdlib.h>
float *shellsort(float *f, int n)
{
int i, j, p;
float x;
p = n/2;
while (p>0)
{
for (i = 0; i < n; i++)
{
j = i;
x = f[i];
while ((j >= p) && (f[j-p] > x))
{
f[j] = f[j-p];
j = j - p;
}
f[j] = x;
}
p = p/2;
}
return f;
}
int main()
{
float farr[] = {6.2, 5.9, 6.1, 6.0, 2.5, 2.1, 3.1, 3.3, 3.2, 6.3};
float *pfarr;
int i;
pfarr = (float*) malloc (10 * sizeof(float));
printf("prima: ");
for (i=0; i<10; i++)
printf("%.1f ", farr[i]);
pfarr = shellsort(farr, 10);
printf("\ndopo : ");
for (i=0; i<10; i++)
printf("%.1f ", pfarr[i]);
printf("\n");
system("pause");
pfarr = NULL;
free (pfarr);
system("pause");
return 0;
}