--- UnitTest.cpp 2004/05/14 18:26:01 8 +++ UnitTest.cpp 2004/05/14 20:57:49 10 @@ -10,6 +10,23 @@ using namespace std; +template +bool contains(const Type& value, DoublyLinkedList& list) +{ + for (Iterator itor(list.iterator()); !itor.end(); itor++) + { + if (*itor == value) return true; + } + + return false; +} + +class VowelVisitor : public Visitor +{ +public: + void visit(const string& value) { if (value.find_first_of("aAeEiIoOuU") == 0) cout << value << '\n'; } +}; + int main(int argc, char* argv[]) { cout.setf(ios_base::boolalpha); @@ -41,5 +58,25 @@ int main(int argc, char* argv[]) cout << *itor << '\n'; } + cout << "contains(3, list) = " << contains(3, list) << '\n' + << "contains(4, list) = " << contains(4, list) << '\n'; + + DoublyLinkedList words; + + words.addFront("Douglas"); + words.addBack("Allen"); + words.addFront("Edward"); + words.addBack("attack"); + words.addFront("Thrift"); + + for (Iterator itor(words.iterator()); !itor.end(); itor++) + { + if (itor->find_first_of("aAeEiIoOuU") == 0) cout << *itor << '\n'; + } + + VowelVisitor vowels; + + words.accept(dynamic_cast*>(&vowels)); + return 0; }