--- UnitTest.cpp 2004/05/14 00:50:29 4 +++ UnitTest.cpp 2004/05/14 18:54:07 9 @@ -10,16 +10,63 @@ 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; +} + int main(int argc, char* argv[]) { + cout.setf(ios_base::boolalpha); + DoublyLinkedList list; list.addFront(1); list.addBack(2); - cout.setf(ios_base::boolalpha); + list.addFront(4); + list.addBack(5); + + // 4 1 2 5 cout << "list.contains(1) = " << list.contains(1) << '\n' - << "list.contains(3) = " << list.contains(3) << '\n'; + << "list.contains(2) = " << list.contains(2) << '\n' + << "list.contains(3) = " << list.contains(3) << '\n' + << "list.contains(4) = " << list.contains(4) << '\n' + << "list.contains(5) = " << list.contains(5) << '\n'; + + list.removeFirst(2); + + // 4 1 5 + + cout << "list.contains(2) = " << list.contains(2) << '\n' + << "list.contains(5) = " << list.contains(5) << '\n'; + + for (Iterator itor(list.iterator()); !itor.end(); itor++) + { + 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'; + } return 0; }