SetSet operator-( Set right )t assert( MaxSize =right MaxSize ) Set temp( MaxSize ) for( int 1=0; 1< MaxSize; 1++) temp. bit Vector[] bit vector[i] &&!right. bit Vector[]; return temp, this01110000110 rights10010100 temp01010000100
Set Set :: operator - ( Set & right ) { assert ( MaxSize == right.MaxSize ); Set temp ( MaxSize ); for ( int i = 0; i < MaxSize; i++ ) temp. bitVector[i] = bitVector[i] && !right.bitVector[i]; return temp; } this right temp 0 1 1 1 0 0 0 0 1 1 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 1 0 0
int Set operator==(Set& right)i assert( MaxSize=- right. MaxSize )3 for( int 1=0; 1< MaxSize; 1++) if( bit Vector[i]! =right. bit Vector[i] return 0: return l this00110000110 right0|010|0010
int Set :: operator == ( Set& right ) { assert ( MaxSize == right.MaxSize ); for ( int i = 0; i < MaxSize; i++) if ( bitVector[i] != right.bitVector[i] ) return 0; return 1; } this right 0 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 1 0 1 0 1 0 i
int Set: SubSet( Set& right t assert( MaxSize=- right. MaxSize ) for( int 1=0; 1< MaxSize; 1++) if (bit Vector[] &&! right. bit Vector[) return 0; return I this00110000110 right 010101
int Set :: SubSet ( Set& right ) { assert ( MaxSize == right.MaxSize ); for ( int i = 0; i < MaxSize; i++) if (bitVector[i] && ! right.bitVector[i]) return 0; return 1; } this right 0 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 1 i
用 有序链表实现集合的抽象数据类型 frst-口 fst-08日17+233549+72 用带表头结点的有序链表表示集合 用有序链表来表示集合时,链表中的每个 结点表示集合的一个成员。 各结点所表示的成员ce1,…,en在链表中 按升序排列,即0<e1<…<en 集合成员可以无限增加。因此,用有序链 表可以表示无穷全集合的子集
first first 08 17 23 35 49 72
集合的有序链表类的定义 template <class Type> class Setlist; template <class Type> class SetNode i friend class SetList<Type> public SetNode(const Type& item ) data(item), link (NULl) private: ype data SetNode<Type>* link
template <class Type> class SetList; template <class Type> class SetNode { friend class SetList<Type>; public: SetNode (const Type& item ) : data (item), link (NULL); private: Type data; SetNode<Type> * link; };