当前位置:首页 > 第五章习题答案
return; }
//元素x并入集合S
bool putX( unsigned *S, unsigned x ) {
if(x>0&&x<=N) {
S[x-1] = 1; return true; }
return false; }
//求并集C=A∪B
void Com( unsigned *C, const unsigned *A,
const unsigned *B )
{
for( int i=0; i //求交集C=A∩B void setInt( unsigned *C, const unsigned *A, const unsigned *B ) { for( int i=0; i //求差集C=A-B void setDif( unsigned *C, const unsigned *A, const unsigned *B ) { for( int i=0; i C[i]= int( A[i]&&!(A[1]&&B[i]) ) ; } //判蕴含,A蕴含于B时返回true bool Inc( const unsigned *A, const unsigned *B ) { for(int i=0; i if(A[i]&&!B[i]) return false; } return true; } //判属于,x∈S时返回true bool In( const unsigned *S, const unsigned x ) { return S[x-1]; } //判空集,S为空集时返回true bool Null( const unsigned *S ) { for( int i=0; i if( S[i]) return false; } return true; } int main() { unsigned A[N]={0}, B[N]={0}, C[N]={0}; unsigned x; cout << \ 1-\ setPut( A ); cout << \ 1-\ setPut( B ); cout<<\ setDisplay( A ); cout<<\ setDisplay( B ); cout << \ cin>>x; cout << \ putX( A, x) ; setDisplay(A); cout << \ Com( C, A, B ); setDisplay( C ); cout << \ setInt( C, A, B ); setDisplay( C ); cout << \ setDif( C, A, B ); setDisplay( C );
共分享92篇相关文档