const
class
pr_mems
intersection
t
x0000 0000 0001 0101
set class
#include <iostream.h> // Implementation of an ADT for type set. const unsigned long int masks[32] = { 0x80000000, 0x40000000, 0x20000000, 0x10000000, 0x8000000, 0x4000000, 0x2000000, 0x1000000, 0x800000, 0x400000, 0x200000, 0x100000, 0x80000, 0x40000, 0x20000, 0x10000, 0x8000, 0x4000, 0x2000, 0x1000, 0x800, 0x400, 0x200, 0x100, 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1}; class set { public: void init (unsigned long int i = 0){ t = i; } bool in(unsigned long int i) const { return bool( (t & masks[i]) != 0); } void pr_mems() const; set sunion(const set& v) const; set intersection(const set& v) const; private: unsigned long int t; }; set set::sunion(const set& v) const{ set temp; temp.init ((t | v.t)); return temp; }
int main(){ set s, t, w; s.init(0x555); t.init(0x10303021); w.init(); cout << " set s = " ; s.pr_mems() ; cout << " set t = " ; t.pr_mems(); w = t.sunion(s); cout << "\nunion: "; w.pr_mems(); w = t.intersection(s); cout << "\nintersection: "; w.pr_mems(); }