代码有点看不懂
#include <iostream>using namespace std;
struct student
{
long number;
float score;
student * next;
};
student * head;
student * create()
{
student * ps;
student * pend;
ps=new student;
cin>>ps->number;cin>>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";
while(head)
{
cout<<head->number<<","<<head->score<<endl;
head=head->next;
}
}
void main()
{
showlist(create());
}
上面红色代码是一样的,有什么不同的作用吗?