【Java开源代码栏目提醒】:以下是网学会员为您推荐的Java开源代码-粗糙集属性约减源代码 - 编程语言,希望本篇文章对您学习有所帮助。
Set.h includeltiostreamgt includeltvectorgt includeltalgorithmgt using namespace std ifndef Set_H define Set_H //定义适合本文的集合Set抽象数据类型-------------------------------------------- class Set public: Set:vec0 Setint A int n //用数组初始化集合 Setconst Set amps //用集合初始化集合 Setvectorltintgt v const Setamp operatorconst Setamp s //集合赋值运算符重载 bool IsEmpty //判断集合是否为空集 int Card //计算集合A的模 void Clear //集合清空 int Findint a //在集合中查找元素a返回位置不存在返回-1 int KeyAtint i //返回集合中i位置的key void SetKeyint index int Val //设置index位置的值为Val void Sort //对集合中的元素按从小到大排序 void Removeint a //在集合中删除元素a得到新的集合 void Addint a //在集合中添加元素a得到新的集合 bool BelongToSet amps //判断集合A是否属于集合B bool operatorSet amps //判断两个集合是否相等 Set SubSet ampsconst //集合A减B计算 Set UnionSet ampsconst //集合A并B计算 Set InterSectSet ampsconst //集合A交B的计算 Set ValueOfAttribute //求属性a值集的值域 vectorltintgt ToIntVector //把该集合转化成整型向量 void Print //在屏幕打印集合A private: vectorltintgt vec endif Set.cpp includequotSet.hquot //集合类Set的实现----------------------------------------------- Set::Setint A int n forint i0 iltn i vec.push_backAi Set::Setconst Set amps vec s.vec Set::Setvectorltintgt v vec v int Set::Card return int vec.size const Setamp Set::operatorconst Setamp s ifthis amps vec s.vec return this bool Set::IsEmpty return vec.empty void Set::Clear vec.clear int Set::Findint a forint i0 iltthis.Card i ifa veci return i return -1 int Set::KeyAtint i return veci void Set::SetKeyint index int Val vecindex Val void Set::Sort sortvec.begin vec.end void Set::Removeint a if-1 Finda vectorltintgt v forvectorltintgt::iterator itvec.begin itltvec.end it ifit a v.push_backit vec v void Set::Addint a vec.push_backa bool Set::BelongToSet amps forint i0 iltint vec.size i if-1 s.Findveci return false return true bool Set::operator Set amps ifthis-gtBelongTos ampamp s.BelongTothis return true else return false Set Set::SubSet ampsconst Set tempvec forint i0 ilts.Card i temp.Removes.KeyAti return temp Set Set::UnionSet ampsconst Set tempvec forint i0 ilts.Card i if-1 temp.Finds.KeyAti temp.Adds.KeyAti return temp Set Set::InterSectSet ampsconst Set tempvec forint i0 iltint vec.size i if-1 s.Findveci temp.Removeveci Set VOfa temp.ValueOfAttribute return VOfa Set Set::ValueOfAttribute Set temp forint i0 iltCard i ifKeyAti INT_MAX temp.AddKeyAti forint ji1 jltCard j ifKeyAti KeyAtj SetKeyj INT_MAX else continue return temp vectorltintgt Set::ToIntVector vectorltintgt temp forint i 0 i lt this-gtCard i temp.push_back this-gtKeyAti return temp void Set::Print vectorltintgt::iterator itvec.begin coutltltquotquot ifvec.empty coutltltit for itltvec.end it coutltltquotquotltltit coutltltquotquot includeltiostreamgt includeltvectorgt includeltalgorithmgt includequotSet.hquot using namespace std ifndef Element_H define Element_H //定义决策表元素类--------------------------------------------------------------- class Element public: El