Set& Set operator -( Set right )i assert( MaxSize --right. MaxSize ) Set temp( MaxSize ) for( int 1=0; 1< MaxSize; 1++) temp. bit Vector1 bit Vector[i] &&!right. bit Vector[] return temp, this Lo110000110 gt[oo10001010 temp[o00000100
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 ) for( int 1-0; 1< MaxSize; 1++) if( bit Vector[ =right. bit Vector1) return 0 return 1 this[00 110000110 right 0010 0101010
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 )i assert( MaxSize = right MaxSize ) for( int 1=0; 1< MaxSize; 1++) if (bit Vector[i] &&! right. bit Vector[D return 0 return 1 this 00110000110 right 999999
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 1 1 0 1 1 0 1 0 1 0 1 i
用有序链表实现集合的抽象数据类型 first- fst-_0817+23+35+49+72 用带表头结点的有序链表表示集合 用有序链表来表示集合时,链表中的每个 结点表示集合的一个成员。 各结点所表示的成员ca213…,en在链表中 按升序排列,即e0<e1<…,<eno 集合成员可以无限增加。因此,用有序链 表可以表示无穷全集合的子集
用有序链表实现集合的抽象数据类型 用带表头结点的有序链表表示集合 first first 08 17 23 35 49 72 ◼ 用有序链表来表示集合时,链表中的每个 结点表示集合的一个成员。 ◼ 各结点所表示的成员 e0 , e1 , …, en 在链表中 按升序排列,即 e0 < e1 < … < en。 ◼ 集合成员可以无限增加。因此,用有序链 表可以表示无穷全集合的子集
集合的有序链表类的定义 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 Type 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; }; 集合的有序链表类的定义