主题:有没有人能帮我该出来
// 请大家帮帮,我刚开始学,什么都不太懂,希望大家给我该具体点
#include<iostream.h>
typedef int elemtype;
class node
{
public:
elemtype data;
node *next;
void initset(node *head)
{
head=NULL;
}
void insert(node *head,elemtype i) //插入
{
node *p=new node;
if(p!=NULL)
{
p->data=i;p->next=head;head=p;
}
}
void dele(node *head,elemtype i) //删除
{
node *p=head,*q=NULL;
while(p)
{
if(p->data=i)break;
else
q=p;p=p->next;
}
q->next=p->next;
delete p;
}
bool find(node *head,elemtype i) //查找
{
node *p=head;
while(p)
{
if(p->data=i)
return true;
else
p=p->next;
}
}
void node::uion(node *head1,node *head2) //交集放在head3里
{
node *head3;
elemtype i;
node *p=head2;
while(p)
{
i=p->data;
if(find(head1,i))
insert(head3,i);
p=p->next;
}
}
};
void main()
{
node *head=NULL;
node *Head1;
node *Head2;
node *Head3;
node *p=head;
int x;
cout<<"输入链表:"<<endl;
cin>>x;
while(x!=-1)
{
insert(Head2,x);
cin>>x;
}
while(x!=-1)
{
insert(Head2,x);
cin>>x;
}
Head3->uion(Head1,Head2);
while(p)
{
cout<<p->data<<" ";
p=p->next;
}
}
//运行之后显示C:\Documents and Settings\Administrator\桌面\tt.cpp(71) : error C2065: 'insert' : undeclared identifier
这是关于一个求交集的问题
#include<iostream.h>
typedef int elemtype;
class node
{
public:
elemtype data;
node *next;
void initset(node *head)
{
head=NULL;
}
void insert(node *head,elemtype i) //插入
{
node *p=new node;
if(p!=NULL)
{
p->data=i;p->next=head;head=p;
}
}
void dele(node *head,elemtype i) //删除
{
node *p=head,*q=NULL;
while(p)
{
if(p->data=i)break;
else
q=p;p=p->next;
}
q->next=p->next;
delete p;
}
bool find(node *head,elemtype i) //查找
{
node *p=head;
while(p)
{
if(p->data=i)
return true;
else
p=p->next;
}
}
void node::uion(node *head1,node *head2) //交集放在head3里
{
node *head3;
elemtype i;
node *p=head2;
while(p)
{
i=p->data;
if(find(head1,i))
insert(head3,i);
p=p->next;
}
}
};
void main()
{
node *head=NULL;
node *Head1;
node *Head2;
node *Head3;
node *p=head;
int x;
cout<<"输入链表:"<<endl;
cin>>x;
while(x!=-1)
{
insert(Head2,x);
cin>>x;
}
while(x!=-1)
{
insert(Head2,x);
cin>>x;
}
Head3->uion(Head1,Head2);
while(p)
{
cout<<p->data<<" ";
p=p->next;
}
}
//运行之后显示C:\Documents and Settings\Administrator\桌面\tt.cpp(71) : error C2065: 'insert' : undeclared identifier
这是关于一个求交集的问题