求助达人 看看到底哪里出错了 谢谢
#include<stdio.h>#include<malloc.h>
#include<math.h>
/*定义两个结构体*/
struct vex{ double x,y,z; struct vex *next;struct vex *last;};
struct vexlist
{
struct vex *mainvex;
struct vex *re_vex[6];
struct vexlist *next;
};
/*创建点的链表,由文件中输入*/
struct vex *creatvex(void)
{
struct vex *p1,*p2,*head;
double x,y,z;
freopen("C:\\data.txt","r",stdin);
head=0;
while(scanf("%f%f%f",&x,&y,&z)!=EOF)
{
p1=(struct vex*)malloc(sizeof(struct vex));
p1->x=x,p1->y=y,p1->z=z,p1->next=0;p1->last=0;
if(!head)
{
head=p1;
p2=p1;
}
else
{
p2->next=p1;
p1->last=p2;
p2=p1;
}
}
return (head);
}
/*创建点列的链表,由点链表中操作得*/
struct vexlist *creatlist(void)
{
struct vexlist *head,*p1,*p2;
int n;
void in(struct vexlist *);
n=0;
head=0;
p1=p2=(struct vexlist *)malloc(sizeof(struct vexlist));
in(p1);
while(p1->next!=0)
{n=n+1;
if(n==1)head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct vexlist *)malloc(sizeof(struct vexlist));
in(p1);
}
return head;
}
/*定义IN函数*/
void in (struct vexlist *vlist)
{
double dis(struct vex *,struct vex *);
static struct vex *p0,*temp,*head;
struct vex *p1,*p2;
int i=0;
head=creatvex();
p0=head;
temp=head;
if(temp->last==0)
temp=p0->next;
else
{temp=head;
p0->last->next=p0->next;
p0->next->last=p0->last;
}
do
{p1=temp;
p2=p1->next;
if(dis(p0,p1)<dis(p0,p2))
{
vlist->re_vex[i]=p1;
p1=p2;
p2=p2->next;
}
else
{
vlist->re_vex[i]=p2;
p2=p2->next;
}
i++;
}while(p2->next==0);
vlist->mainvex=p0;
if(p0->last!=0)
{
p0->last->next=p0;
p0->next->last=p0;
}
p0=p0->next;
}
/*定义距离函数dis*/
double dis(struct vex *N,struct vex *M)
{
double t;
t=sqrt((N->x-M->x)*(N->x-M->x)+(N->y-M->y)*(N->y-M->y)+(N->z-M->z)*(N->z-M->z));
return t;
}
/*检测*/
void print(struct vexlist *head)
{
struct vexlist *p;
p=head;
if(head!=0)
do
{
printf("%f,%f,%f;\n",&p->mainvex->x,&p->mainvex->y,&p->mainvex->z);
p=p->next;
}while(p!=0);
}
void main()
{
void print(struct vexlist *head);
struct vex *creatvex(void);
struct vexlist *creatlist(void);
struct vexlist *p;
p=creatlist();
print(p);
}