templatestatic void set_union(const Set & A, const Set & B, Set & AuB) { Set::iterator ai = A.begin(); Set::iterator bi = B.begin(); while (ai != A.end() && bi != B.end()) if (*ai < *bi) AuB.insert(*ai++); else { AuB.insert(*bi++); if (*ai == *bi) ai++; } AuB.insert(ai, A.end()); AuB.insert(bi, B.end()); }
templatestatic void multiset_union(const Set & A, const Set & B, Set & AuB) { Set::iterator ai = A.begin(); Set::iterator bi = B.begin(); while (ai != A.end() && bi != B.end()) if (*ai <= *bi) AuB.insert(*ai++); else AuB.insert(*bi++); AuB.insert(ai, A.end()); AuB.insert(bi, B.end()); }
templatestatic void set_difference(const Set & A, const Set & B, Set & AdB) { Set::iterator ai = A.begin(); Set::iterator bi = B.begin(); while (ai != A.end() && bi != B.end()) if (*ai < *bi) AdB.insert(*ai++); else if (*ai == *bi) { ai++; bi++; } else bi++; AdB.insert(ai, A.end()); }
S, an element x of S is the majority of
S if S.count(x) > S.size()/2
x and y from S
x != y then throw them both out
x == y, then they may be in the majority; remember them
S is empty
S
This page last modified on 26 July 2000.