请大家帮忙找出错误所在.
bensu 2003-08-23 12:57:05 #include<string.h>
#include<iostream.h>
struct name
{
char student_name[20];
name *link;
};
class student
{
public:
student();
~student();
int check();
int insert();
void show();
private:
name *head,*tail;
};
student::student()
{
head=tail=NULL;
}
student::~student()
{
name *temp=head;
while(temp->link!=NULL)
{
delete temp;
temp=temp->link;
}
}
int student::check()
{
char *a;
cout<<"please input the name that you want tocheck"<<endl;
cin>>a;
name *temp=head;
while(temp->link!=NULL)
{
if(!strcmp(temp->student_name,a))
{
cout<<"the name is found!";
return 1;
}
else
temp=temp->link;
}
if(temp->link==NULL)
{
cout<<"the name is not in the link";
return 0;
}
}
int student::insert()
{
name *temp=new name;
if(temp==NULL)
return 0;
cout<<"input the name you want to insert"<<endl;
cin>>temp->student_name;
if(head==NULL)
{
head=tail=temp;
delete temp;
}
else
{
tail->link=temp;
tail=temp;
delete temp;
}
return 1;
}
void student::show()
{
name *temp=head;
while(temp->link!=NULL)
{
cout<<temp->student_name<<endl;
temp=temp->link;
}
}
void main()
{
student s;
char *a;
int flag=0,order;
while(flag)
{
cout<<"1.insert"<<endl<<"2.check"<<endl<<"3.show all"<<endl<<"4.exit"<<endl;
cin>>order;
switch(order)
{
case'1':
s.insert();
break;
case'2':
s.check()
break;
case'3':
s.show();
break;
case'4':
flag=0;
}
}
}
//代码的作用是用链表储存名字,并可以查找出某个名字是否在表里也可以显示出所有的名字。
//有菜单选择。
可以通过编译,但是运行不了.