首页上一页 1 下一页尾页 1 条记录 1/1页
创建链表有多少方法?
发表在C语言图书答疑
2009-05-23
是否精华
是
否
版块置顶:
是
否
struct student
{
int num;
float score;
student*next;
};
student*create();
void main()
{
student*head;
head=create();
}
student*create
{
student*head,*tail,*p;
float score;
int num,size=sizeof(student);
head=tail=NULL;
cout<<"please enter num,score:";
cin>>p->num>>p->score;
while(num)
{
p=new student;
p->num=num;
p->score;
p->next=NULL;
if(head=NULL)
head=p;
else
tail->next=p;
tail=p;
cin>>p->num>>p->score;
}
return head;
}
int main()
{
student c={"kaka"k,23,NULL};
student b={"deco",27,&c};
student a={"terry",33,&b};
student*head=&a;
student*pointer=head;
cout<<"head->";
while(pointer)
{
cout<<(*pointer).name<<"->"<<(*pointer).age<<"->";
pointer=(*pointer).next;
}
cout<<"End"<<endl;
return 0;
}