ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/ccscs20/UnitTest.cpp
(Generate patch)

Comparing UnitTest.cpp (file contents):
Revision 4 by Douglas Thrift, 2004-05-13T17:50:29-07:00 vs.
Revision 10 by Douglas Thrift, 2004-05-14T13:57:49-07:00

# Line 10 | Line 10
10  
11   using namespace std;
12  
13 + template<typename Type>
14 + bool contains(const Type& value, DoublyLinkedList<Type>& list)
15 + {
16 +        for (Iterator<Type> itor(list.iterator()); !itor.end(); itor++)
17 +        {
18 +                if (*itor == value) return true;
19 +        }
20 +
21 +        return false;
22 + }
23 +
24 + class VowelVisitor : public Visitor<string>
25 + {
26 + public:
27 +        void visit(const string& value) { if (value.find_first_of("aAeEiIoOuU") == 0) cout << value << '\n'; }
28 + };
29 +
30   int main(int argc, char* argv[])
31   {
32 +        cout.setf(ios_base::boolalpha);
33 +
34          DoublyLinkedList<int> list;
35  
36          list.addFront(1);
37          list.addBack(2);
38 <        cout.setf(ios_base::boolalpha);
38 >        list.addFront(4);
39 >        list.addBack(5);
40 >
41 >        // 4 1 2 5
42  
43          cout << "list.contains(1) = " << list.contains(1) << '\n'
44 <                << "list.contains(3) = " << list.contains(3) << '\n';
44 >                << "list.contains(2) = " << list.contains(2) << '\n'
45 >                << "list.contains(3) = " << list.contains(3) << '\n'
46 >                << "list.contains(4) = " << list.contains(4) << '\n'
47 >                << "list.contains(5) = " << list.contains(5) << '\n';
48 >
49 >        list.removeFirst(2);
50 >
51 >        // 4 1 5
52 >
53 >        cout << "list.contains(2) = " << list.contains(2) << '\n'
54 >                << "list.contains(5) = " << list.contains(5) << '\n';
55 >
56 >        for (Iterator<int> itor(list.iterator()); !itor.end(); itor++)
57 >        {
58 >                cout << *itor << '\n';
59 >        }
60 >
61 >        cout << "contains(3, list) = " << contains(3, list) << '\n'
62 >                << "contains(4, list) = " << contains(4, list) << '\n';
63 >
64 >        DoublyLinkedList<string> words;
65 >
66 >        words.addFront("Douglas");
67 >        words.addBack("Allen");
68 >        words.addFront("Edward");
69 >        words.addBack("attack");
70 >        words.addFront("Thrift");
71 >
72 >        for (Iterator<string> itor(words.iterator()); !itor.end(); itor++)
73 >        {
74 >                if (itor->find_first_of("aAeEiIoOuU") == 0) cout << *itor << '\n';
75 >        }
76 >
77 >        VowelVisitor vowels;
78 >
79 >        words.accept(dynamic_cast<Visitor<string>*>(&vowels));
80  
81          return 0;
82   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines