-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCDLL-Tester.cpp
151 lines (115 loc) · 4.04 KB
/
SCDLL-Tester.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <iostream>
#include "SortedCircularDLL.h"
using namespace std;
int main()
{
SortedCircularDLL<int> list1;
cout << endl;
cout << "- Is the list empty?\n";
if(list1.isEmpty())
cout << "Yes.\n";
else
cout << "No.\n";
cout << endl; //=======================================
cout << "- Adding -1, 3, 1, -10, 5, 7, 5, 10, 2, 0 sorted from smaller to bigger...\n";
list1.add(-1);
list1.add(3);
list1.add(-10);
list1.add(5);
list1.add(7);
list1.add(5);
list1.add(10);
list1.add(2);
list1.add(0);
cout << endl; //=======================================
cout << "- Printing list...\n";
cout << list1;
cout << endl; //=======================================
cout << "- Is the list empty?\n";
if(list1.isEmpty())
cout << "Yes.\n";
else
cout << "No.\n";
cout << endl; //=======================================
cout << "- Printing list in reverse...\n";
list1.printReverse();
cout << endl; //=======================================
cout << "- Testing copy constructor with [list2(list1)]...\n";
SortedCircularDLL<int> list2(list1);
cout << list2;
cout << endl; //=======================================
cout << "- Removing 5...";
if(list1.remove(5))
cout << "removed!\n";
else
cout << "not removed.\n";
cout << "- Printing list...\n";
cout << list1;
cout << endl; //=======================================
cout << "- Testing operator overload '=' with [list3 = list1]...done!\n";
SortedCircularDLL<int> list3 = list1;
cout << " Printing copied list...\n";
cout << list3;
cout << endl; //=======================================
cout << "- First node of [list3] is " << list3.getFirst();
cout << "\n- Last node of [list3] is " << list3.getLast();
cout << endl; //=======================================
cout << "\n- Number of copies of element '11': " << list1.count(11);
cout << endl; //=======================================
cout << "\n- First index of element '3': " << list1.firstIndex(3);
cout << "\n- Last index of element '11': " << list1.lastIndex(11);
cout << endl; //=======================================
cout << "\n- Removing all copies of '11' from copied list [list3]...";
cout << "removed " << list3.removeAll(11) << " copies.\n";
cout << " Printing affected list...\n";
cout << list3;
cout << "\n- Setting in [list3] a new element '18' at position 8...\n";
list3.setAt(8, 18);
cout << " Printing list [list3]...\n";
cout << list3;
cout << endl; //=======================================
cout << "- Removing at position 8 in [list3]...";
if(!list3.removeAt(8))
cout << "position is out of range.\n";
else
cout << "done!\n";
cout << endl; //=======================================
cout << "- Printing all three lists...";
cout << "\n [list1]: ";
cout << list1;
cout << "\n [list2]: ";
cout << list2;
cout << "\n [list3]: ";
cout << list3;
cout << endl; //=======================================
cout << "\n- Printing all three lists in reverse...";
cout << "\n [list1]: ";
list1.printReverse();
cout << "\n [list2]: ";
list2.printReverse();
cout << "\n [list3]: ";
list3.printReverse();
cout << endl; //=======================================
cout << "- Clearing [list1]...\n";
list1.clear();
cout << " Is [list1] empty?\n";
if(list1.isEmpty())
cout << " Yes.\n";
else
cout << " No.\n";
cout << endl; //=======================================
cout << "- Adding 20, 40, 32, 10, 15, 7, 46...\n";
list1.add(20);
list1.add(40);
list1.add(32);
list1.add(10);
list1.add(15);
list1.add(7);
list1.add(46);
cout << " Printing [list1]: ";
cout << list1;
cout << endl; //=======================================
cout << "- Element in position 4: " << list1.getAt(4);
cout << endl << endl;
return 0;
}