template <class Type> class SetNode i friend class Setlist<type>; publics SetNode (const Type item): data(item), link (null) private: ype data; SetNode<Type> * link template <class Type> class setlist i private: SetNode<Type> first, last publics
template <class Type> class SetNode { friend class SetList<Type>; public: SetNode (const Type & item ) : data (item), link (NULL); private: Type data; SetNode<Type> *link; }; template <class Type> class SetList{ private: SetNode<Type> *first, *last; public:
Netlist void MakeEmpty o; int AddMember( const Type x ); int Delmember( const Type & x ) Setlist<Type> operator =( Setlist< type> &e right ) Setlist<type>& operator + Setlist<type> right i Setlist<Type> operator * SetList<Type> &e right) Setlist<type>& operator-( Setlist<Type> &e right) int Contains( const Type & x);
SetList ( ); void MakeEmpty ( ); int AddMember( const Type & x ); int DelMember ( const Type & x ); SetList<Type> & operator = ( SetList<Type> & right ); SetList<Type> & operator + ( SetList<Type> & right ); SetList<Type> & operator * ( SetList<Type> & right ); SetList<Type> & operator - ( SetList<Type> & right ); int Contains ( const Type & x );
int operator =- SetList< Type>& right ) Type Min (; Type Max (; 集合构造函数 template <class Type> void Setlist<Type>:: Setlistoi SetNode<Type> first=*last= new SetNode<Type>(0);
int operator == ( SetList<Type> & right ); Type & Min ( ); Type & Max ( ); } 集合构造函数 template <class Type> void SetList<Type> :: SetList ( ) { SetNode<Type> *first = *last = new SetNode<Type>(0); }
集合的搜索、加入和删除操作 template <class Type int Setlist<type> Contains(const Type &x)i SetNode<type> *temp=first-link while( temp !=nuLL & temp-data<x) temp=temp-link if (temp NULL & temp-data==x) return I else return o
集合的搜索、加入和删除操作 template <class Type> int SetList<Type> :: Contains(const Type & x ) { SetNode<Type> *temp = first→link; while ( temp != NULL && temp→data < x ) temp = temp→link; if (temp != NULL && temp→data == x) return 1; else return 0; }
template <class Type> int Setlist<Type> AddMember( const Type &x)i Jpe>米 SetNode<Type> p=first-link, * q=first while(p!=NULL&&p→data≤x) {q=p;p=p-→link; if (p = nULL & p-data==x)return 0 SetNode<type>*s=new SetNode(x); S→lnk=p;q-link=s; if (p==NULL )last=s, return 1
template <class Type> int SetList<Type> :: AddMember ( const Type & x ) { SetNode<Type> *p = first→link, *q = first; while ( p != NULL && p→data < x ) { q = p; p = p→link; } if ( p != NULL && p→data == x ) return 0; SetNode<Type> *s = new SetNode (x); s→link = p; q→link = s; if ( p == NULL ) last = s; return 1; }