注册 登录
编程论坛 C++教室

如何创建空头链表,如果数据域不放东西的话,组建是就会出现错误。如下

一眼的笑意 发布于 2008-10-01 20:43, 511 次点击
#include<iostream.h>
#define CIR struct circle
struct circle{
    int r;
    double x;
    double y;
    struct circle *next;
};
void main()
{
    CIR *head,*pb,*pf;
    cout<<"输入要创建的圆的个数";
    int n;
    cin>>n;
    cout<<"输入圆半径及圆心坐标";
    for(int i=1;i<=n;i++)
    {
        pb=new CIR;
        cin>>pb->r>>pb->x>>pb->y;
        if(i==1)
            head->next=pb;
        else
            pf->next=pb;
        pb->next=NULL;
        pf=pb;
    }
}
0 回复
1