// see apset.h const int SDEFAULT_SIZE = 10; // default initial set size template apset::apset() : myList(SDEFAULT_SIZE), myCount(0) { } template bool apset::contains(const itemType & item) const { int loc = find(item); return loc != -1; } template int apset::size() const { return myCount; } template void apset::print(ostream & output) const { int k; output << "(" << endl; for(k=0; k < myCount; k++) { output << "\t" << myList[k] << endl; } output << ")" << endl; } template void apset::add(const itemType & item) { int loc = find(item); if (loc == -1) { if (myCount >= myList.length()) { myList.resize(myCount * 2); } myList[myCount] = item; myCount++; } } template void apset::remove(const itemType & item) { int loc = find(item); if (loc != -1) { myList[loc] = myList[myCount-1]; myCount--; } } template void apset::makeEmpty() { myCount = 0; } template int apset::find(const itemType & item) const { int k; for(k=0; k < myCount; k++) { if (myList[k] == item) return k; } return -1; } template const apset& apset::operator *= (const apset & rhs) { apset result; int k; int length; if (size() < rhs.size()) { length = size(); for(k=0; k < length; k++) { if (rhs.contains(myList[k])) { result.add(myList[k]); } } } else { length = rhs.size(); for(k=0; k < length; k++) { if (contains(rhs.myList[k])) { result.add(myList[k]); } } } *this = result; return *this; } template const apset& apset::operator += (const apset & rhs) { int k; int length = rhs.size(); for(k=0; k < length; k++) { if (! contains(rhs.myList[k])) { add(rhs.myList[k]); } } return *this; }