按照输入的点,任意两个点的距离大小进行快速排序,哪里错了?
#include<stdio.h>#include<math.h>
#include<stdlib.h>
#define M 10
typedef struct {
int x;
int y;
int z;
}Point[M];
double distance(int x,int y,int z,int x1,int y1,int z1)
{
return ((double)sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1)+(z-z1)*(z-z1)));
}
int f(const void *c,const void *d)
{
return (*(int*)c- *(int*)d);
}
int main()
{
Point point;
int k,n;
int x1,y1,z1;
int i=0;
int j;
int t=0;
double sum[50];
scanf("%d",&k);
for(i=0;i<k;i++)
{
scanf("%d%d%d",&x1,&y1,&z1);
point[i].x=x1;
point[i].y=y1;
point[i].z=z1;
i++;
}
for(j=0;j<i;j++)
{
for(k=j+1;k<i;k++)
{
sum[t]=distance(point[j].x,point[j].y,point[j].z,point[k].x,point[k].y,point[k].z);
}
}
qsort(sum,i,sizeof(int),f);
n=i;
for(i=0;i<n;i++)
printf("%lf ",sum[i]);
return 0;
}