请教高手!! 一个c++链表问题

来源:百度知道 编辑:UC知道 时间:2024/07/07 19:41:16
#include<iostream.h>
struct SC
{char name[100];double result;SC*next;};

void createlist(SC*&head)
{SC*s,*p;
int i;
s=new SC;
cout<<"1or0:";
cin>>i;
if(i!=0)
{ cout<<"姓名:";
cin>>s->name;
cout<<"分数:";
cin>>s->result;
cout<<"1or0:";
cin>>i;
}
else return;
while(i!=0)
{if(head==NULL)
{head=s;
p=head;}
else
{p->next=s;
p=s;
s=new SC;
cout<<"姓名:";
cin>>s->name;
cout<<"分数:";
cin>>s->result;
cout<<"1or0:";
cin>>i; }
}
p->next=s;
p=s;
p->next=NULL;
delete s;
return;
}
void showlist(SC*head)
{
{while(head)
{cout<<head->name<&

createlist(...)很繁琐,另外,while后的delete s;可能导致整个list无效,因为删除了最后一个节点...

加个freeListAll(...)会不会安全些?

VC6.0测试
0 error(s), 0 warning(s)