创建一个单链表,编译不能通过,那位兄弟帮忙看下找出错误,谢谢!
//创建一个单链表#include<iostream.h>
struct student
{
long number;
float score;
student *next;
};//定义一结构类型
struct *head;//链首指针
struct *creat()
{
student *ps;//创建的节点指针
student *pend;//链尾指针,用于在其后面插入节点
ps=new student;//新建一个结构类型结点,准备插入链表
cin>>ps->number>>ps->score;//给新建结点赋值
head=NULL;
pend=ps;
while(ps->number!=0)
{
if(head==NULL)
head=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\n";
while(head)
{
cout<<head->number<<","<<head->score<<endl;
head=head->next;
}
}
void main()
{
showlist(creat());
}