#include<iostream.h>
#include<malloc.h>
#include<stdlib.h>
struct point{
float x;
float y;
point *next;
};
point * create(int count)
{
point *p,*h,*s;
h=(point *)malloc(sizeof(struct point));
if(h==NULL)
{
cout<<"Malloc memory error"<<endl;
}
/********************************************Init head**********************************/
h->x=NULL;
h->y=NULL;
h->next=NULL;
/********************************************Init head**********************************/
p=h;
for(int i=0;i<count;i++)
{
s=(point *)malloc(sizeof(struct point));
if(s==NULL)
{
cout<<"Malloc memory error"<<endl;
}
cout<<"cin X"<<endl;
cin>>s->x;
cout<<"cin Y"<<endl;
cin>>s->y;
s->next=NULL;
p->next=s;
p=p->next;
}
return h;
}
int main(void)
{
point *xy;
int number;
cout<<"请输入坐标点的数目"<<endl;
cin>>number;
xy=create(number);
if(xy!=NULL)
{
cout<<xy->x<<","<<xy->y<<endl;
xy=xy->next;
}
return 0;
}
compile and link is ok ,but can't write correctlly