C++ 实现整数集合类:并集、交集运算
//StudybarCommentBegin
#include
int i,j,t;
if(n>0)
{
for (i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
for(i=0;i<n;i++)
{
cout<<a[i]<<' ';
}
}
else
{cout<<'empty';
}
}
};
//StudybarCommentEnd //StudybarCommentBegin int main( ) { Cassemblage z1, z2, x3; int i, n1, n2, a1[1000], a2[1000]; cin >> n1; for(i=0; i<n1; i++) { cin >> a1[i]; } z1.Set(a1, n1);
cin >> n2;
for(i=0; i<n2; i++)
{
cin >> a2[i];
}
z2.Set(a2, n2);
x3=z1+z2;
x3.Show();
cout << endl;
x3=z1-z2;
x3.Show();
return 0;
}
//StudybarCommentEnd
原文地址: https://www.cveoy.top/t/topic/oOUr 著作权归作者所有。请勿转载和采集!