1 |
Douglas Thrift |
1 |
// Unit Test |
2 |
|
|
// |
3 |
|
|
// Douglas Thrift |
4 |
|
|
// |
5 |
|
|
// $Id$ |
6 |
|
|
|
7 |
Douglas Thrift |
4 |
#include <iostream> |
8 |
|
|
#include <string> |
9 |
Douglas Thrift |
1 |
#include "DoublyLinkedList.hpp" |
10 |
|
|
|
11 |
Douglas Thrift |
4 |
using namespace std; |
12 |
|
|
|
13 |
Douglas Thrift |
9 |
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 |
Douglas Thrift |
1 |
int main(int argc, char* argv[]) |
25 |
|
|
{ |
26 |
Douglas Thrift |
6 |
cout.setf(ios_base::boolalpha); |
27 |
|
|
|
28 |
Douglas Thrift |
1 |
DoublyLinkedList<int> list; |
29 |
|
|
|
30 |
Douglas Thrift |
4 |
list.addFront(1); |
31 |
|
|
list.addBack(2); |
32 |
Douglas Thrift |
6 |
list.addFront(4); |
33 |
|
|
list.addBack(5); |
34 |
Douglas Thrift |
4 |
|
35 |
Douglas Thrift |
7 |
// 4 1 2 5 |
36 |
|
|
|
37 |
Douglas Thrift |
4 |
cout << "list.contains(1) = " << list.contains(1) << '\n' |
38 |
Douglas Thrift |
6 |
<< "list.contains(2) = " << list.contains(2) << '\n' |
39 |
|
|
<< "list.contains(3) = " << list.contains(3) << '\n' |
40 |
|
|
<< "list.contains(4) = " << list.contains(4) << '\n' |
41 |
|
|
<< "list.contains(5) = " << list.contains(5) << '\n'; |
42 |
Douglas Thrift |
4 |
|
43 |
Douglas Thrift |
6 |
list.removeFirst(2); |
44 |
|
|
|
45 |
Douglas Thrift |
7 |
// 4 1 5 |
46 |
Douglas Thrift |
6 |
|
47 |
Douglas Thrift |
7 |
cout << "list.contains(2) = " << list.contains(2) << '\n' |
48 |
|
|
<< "list.contains(5) = " << list.contains(5) << '\n'; |
49 |
|
|
|
50 |
Douglas Thrift |
8 |
for (Iterator<int> itor(list.iterator()); !itor.end(); itor++) |
51 |
Douglas Thrift |
7 |
{ |
52 |
|
|
cout << *itor << '\n'; |
53 |
|
|
} |
54 |
|
|
|
55 |
Douglas Thrift |
9 |
cout << "contains(3, list) = " << contains(3, list) << '\n' |
56 |
|
|
<< "contains(4, list) = " << contains(4, list) << '\n'; |
57 |
|
|
|
58 |
|
|
DoublyLinkedList<string> words; |
59 |
|
|
|
60 |
|
|
words.addFront("Douglas"); |
61 |
|
|
words.addBack("Allen"); |
62 |
|
|
words.addFront("Edward"); |
63 |
|
|
words.addBack("attack"); |
64 |
|
|
words.addFront("Thrift"); |
65 |
|
|
|
66 |
|
|
for (Iterator<string> itor(words.iterator()); !itor.end(); itor++) |
67 |
|
|
{ |
68 |
|
|
if (itor->find_first_of("aAeEiIoOuU") == 0) cout << *itor << '\n'; |
69 |
|
|
} |
70 |
|
|
|
71 |
Douglas Thrift |
1 |
return 0; |
72 |
|
|
} |