-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_list.cpp
78 lines (67 loc) · 1.33 KB
/
test_list.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//compile with g++ -std=c++11 -Wall -Werror -pedantic-errors -g -o test_list list_test.cpp list.h
#include <iostream>
#include "list.h"
using std::cout;
using std::endl;
using mtm::List;
using mtm::ValueNotInList;
void print_list(List<int>& l)
{
cout << "The List is: ";
for (List<int>::ListIterator i = l.begin(); i != l.end(); ++i)
{
cout << *i << " ";
}
cout << endl;
}
List<int> create_long_list()
{
List<int> l = List<int>();
for (int i = 10; i > 0; i--)
{
l.add(i);
print_list(l);
}
return l;
}
void print_contains(List<int> l, int i)
{
if(l.contains(i))
{
cout << "List contains the number " << i << endl;
}
else
{
cout << "List does not contain number" << i << endl;
}
}
int main()
{
List<int> l = create_long_list();
print_list(l);
l.remove(3);
print_list(l);
l.remove(8);
print_list(l);
l.remove(9);
print_list(l);
print_contains(l, 1);
print_contains(l, 18);
print_contains(l, 10);
print_contains(l, 8);
List<int> l1(l);
print_list(l1);
l1 = l;
print_list(l1);
l1.remove(10);
print_list(l1);
l1.remove(1);
l1.remove(2);
l1.remove(4);
l1.remove(5);
l1.remove(6);
print_list(l1);
l1.remove(7);
l1.add(1);
print_list(l1);
}