|
struct student
{
long number;
float score;
student * next;
};
student * head; //链首指针
student * creat() //创建链表
{
student *ps; //结点指针
student *pend; //链尾指针
ps=new student; //分配内存空间,建立一个节点,准被插入链表
cin>>ps->number>>ps->score;
head=NULL; //开始链表为空
pend=ps;
while(ps->number!=0)
{
if(head==NULL)
pend=ps;
else
pend->next=ps;
pend=ps;
ps=new student;
cin>>ps->number>>ps->score;
}
pend->next=NULL;
delete ps;
return head;
}
void showlist(student * head)
{
cout<<"now the items of list are:"<<endl;
while(head)
{
cout<<head->number<<","<<head->score<<endl;
head=head->next;
}
}
void main()
{
showlist (creat());
}
输入后,显示now the items of list are: 下面就不显示了,输出有什么错误?? |
|