怎么改?
#include <iostream>using namespace std;
struct Node
{
double value;
Node *next;
};
class collection
{
private:
Node *head;
Node *tail;
public:
collection()
{
initial();
}
void initial()
{
head=new Node;
head->next=NULL;
tail=head;
}
void clear()
{
Node *index;
do{
index=head;
head=head->next;
delete index;
}while(head != NULL);
initial();
// cout<<"5656656";
}
void input()
{
cout<<"输入(#结束):";
char ch[10];
cin>>ch;
while( ch[0] != '#')
{
double a= atof(ch);
this->addValue(a);
cin>>ch;
}
}
Node * search(Node *indexi)
{
Node *index=head->next;
while(index != NULL)
{
if( index->value == indexi->value )
break;
index=index->next;
}
if(index !=NULL)
{
return index;
}
else return NULL;
}
int addValue(double newValue)
{
// cout<<"55";
Node *index=new Node;
index->next=NULL;
index->value=newValue;
if( search(index) == NULL )
{
tail->next=index;
tail=index;
tail->next=NULL;
return 1;
}
else return 0;
}
int addValue(Node *newNode)
{
if( search(newNode) == NULL )
{
Node *temp=new Node;
temp->value=newNode->value;
tail->next=temp;
tail=temp;
tail->next=NULL;
return 1;
}
else return 0;
}
int DeleteValue(double newValue)
{
Node *temp=head;
Node *temp1=head->next;
while( temp1 !=NULL)
{
if(temp1->value == newValue)
break;
temp=temp1;
temp1=temp1->next;
}
if(temp1 != NULL)
{
if(temp1->next==NULL)
{
tail=temp;
tail->next=NULL;
delete temp1;
}
else{
temp->next=temp1->next;
temp1->next=NULL;
delete temp1;
}
return 1;
}
return 0;
}
void output()
{
cout<<"该集合:";
Node *index=head->next;
int count=0;
while( index !=NULL)
{
cout<<index->value<<" ";
index=index->next;
count++;
}
cout<<endl;
cout<<"该集合大小:"<<count<<endl;
}
/* collection operator =(const collection & x1) const
{
collection temp;
temp.head=x1.head;
Node *index=x1.head->next;
temp.tail=temp.head;
while( index !=NULL)
{
temp
}
}*/
void bin(collection *a1,collection *a2)
{
Node *index=head->next;
while(index !=NULL)
{
a2->addValue(index);
index=index->next;
}
// a2->output();
index=a1->head->next;
while(index !=NULL)
{
a2->addValue(index);
index=index->next;
}
}
void jiao(collection *a1,collection *a2)
{
Node *index=head->next;
while(index !=NULL)
{
if( a1->search(index) !=NULL )
{
Node *temp=new Node;
temp->value=index->value;
a2->addValue(index);
}
index=index->next;
}
}
void cha(collection *a1,collection *a2)
{
Node *index=head->next;
while(index !=NULL)
{
if(a1->search(index) ==NULL)
a2->addValue(index);
index=index->next;
}
}
};