64,650
社区成员
发帖
与我相关
我的任务
分享
#include <iostream.h>
typedef struct student
{
int num;
struct student *next;
}M;
M *creat()
{
M *head,*ps,*pend;
head=NULL;
ps=new M;
cin>>ps->num;
pend=ps;
while(ps->num>0)
{
if(head==NULL)
head=ps;
else
pend->next=ps;//把ps所指向的接点连接到表末
pend=ps;//第一次时候这句和第九行的那句重复了,但是为了和以后的链表连接这句是必要的
ps=new M;
ps->next=NULL;
cin>>ps->num;
}
pend->next=NULL; //here
delete ps;
return head;
}
void showlist(M *head)
{
cout <<"now the items of list \n";
while(head) // here 多了;
{
cout <<head->num <<" ";
head=head->next;
}
}
void main()
{
showlist(creat()); //
}