求助达人看看哪里错了谢谢
#include<stdio.h>#include<malloc.h>
#include<math.h>
/*定义两个结构体*/
struct vex{ int 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;
int x,y,z;
freopen("C:\\data.txt","r",stdin);
head=0;
while(scanf("%d%d%d",&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)
{
int dis(struct vex *,struct vex *);
static struct vex *p0,*temp,*head;
struct vex *p1,*p2;
int i=0;
head=creatvex();
p0=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;
p0=p0->next;
}
/*定义距离函数dis*/
int dis(struct vex *N,struct vex *M)
{
int 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("%d,%d,%d;\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);
}