正在加载图片...
第7章集合与搜索 SenNode <Type> 'pb=right first->link; ∥rgh集合的链扫描指针 SetNode <Type> "pa, pc; this集合的链扫描指针和结果链的存放指针 while( pa I=NULL)( ∥首先把集合this的所有元素复制到结果链 pc->link= new SetNode<Type>(pa->data ) pa= pa-> ink; pc=pc->link; while( pb I= NULL)& ∥将集合righ中元素一个个拿出到this中查重 while(pa I= NULL & pa->data I= pb->data )pa=pa->link ∥在集合this中未出现,链入到结果链 c->ink= new SetNode<Type>( pa->data ) pc=pc-> pb=pb-> link pe->link=NULL; last=pc; ∥链表收尾 return temp; (2)operator *O template <class Type> Set <Type>& Set <Type>: operator'( Set <Type>& right)t ∥求集合this与集合rght的交,计算结果通过临时集合temp返回,this集合与rght集合不变 ∥rght集合的链扫描指针 Set <Type> temp; SetNode <Type> "pc= temp first; ∥结果链的存放指针 while(pb l= NULL)& ∥将集合rght中元素一个个拿出到this中查重 SetNode<Type> "pa=firsf->link; ∥this集合的链扫描指针 while( pa I= NULL)( /两集合公有的元素,插入到结果链 dpc->link= new SetNode<Type>( pa->data )i pc=pc->link; 3 } pb= pb-> ink; pe>ink=NULL; last=pc; ∥置链尾指针 eturn lemp, ()operator-( template <class Type> Set <Type>& Set <Type>:: operator-( Set <Type>& right)& ∥集合this与集合rght的差,计算结果通过临时集合lemp返回,this集合与 right集合不变。 SetNode<Type> "pa=firsf->link; /this集合的链扫描指针 SetNode<Type> 'pc=temp->first; ∥结果链的存放指针第 7 章 集合与搜索 57 SetNode <Type> *pb = right.first->link; //right 集合的链扫描指针 SetNode <Type> *pa, *pc; //this 集合的链扫描指针和结果链的存放指针 Set <Type> temp; pa = first->link; pc = temp.first; while ( pa != NULL ) { //首先把集合 this 的所有元素复制到结果链 pc->link = new SetNode<Type> ( pa->data ); pa = pa->link; pc = pc->link; } while ( pb != NULL ) { //将集合 right 中元素一个个拿出到 this 中查重 pa = first->link; while ( pa != NULL && pa->data != pb->data ) pa = pa->link; if ( pa == NULL ) //在集合 this 中未出现, 链入到结果链 { pc->link = new SetNode<Type> ( pa->data ); pc = pc->link; } pb = pb->link; } pc->link = NULL; last = pc; //链表收尾 return temp; } (2) operator * ( ) template <class Type> Set <Type>& Set <Type> :: operator * ( Set <Type>& right ) { //求集合 this 与集合 right 的交, 计算结果通过临时集合 temp 返回,this 集合与 right 集合不变。 SetNode<Type> *pb = right.first->link; //right 集合的链扫描指针 Set <Type> temp; SetNode <Type> *pc = temp.first; //结果链的存放指针 while ( pb != NULL ) { //将集合 right 中元素一个个拿出到 this 中查重 SetNode<Type> *pa = first->link; //this 集合的链扫描指针 while ( pa != NULL ) { if ( pa->data == pb->data ) //两集合公有的元素, 插入到结果链 { pc->link = new SetNode<Type> ( pa->data ); pc = pc->link; } pa = pa->link; } pb = pb->link; } pc->link = NULL; last = pc; //置链尾指针 return temp; } (3) operator - ( ), template <class Type> Set <Type>& Set <Type> :: operator - ( Set <Type>& right ) { //求集合 this 与集合 right 的差, 计算结果通过临时集合 temp 返回,this 集合与 right 集合不变。 SetNode<Type> *pa = first->link; //this 集合的链扫描指针 Set <Type> temp; SetNode<Type> *pc = temp->first; //结果链的存放指针
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有