-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableDriver.cpp
99 lines (73 loc) · 2.21 KB
/
TableDriver.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
#include "TableSortedList.h"
#include "ListArray.h"
using CSC2110::ListArray;
#include "ListArrayIterator.h"
using CSC2110::ListArrayIterator;
#include "CD.h"
using CSC2110::CD;
#include "Text.h"
using CSC2110::String;
#include <iostream>
using namespace std;
void deleteCDs(ListArray<CD>* list)
{
ListArrayIterator<CD>* iter = list->iterator();
while(iter->hasNext())
{
CD* cd = iter->next();
delete cd;
}
delete iter;
}
int main()
{
ListArray<CD>* cds = CD::readCDs("cds.txt");
int num_items = cds->size();
cout << num_items << endl;
TableSortedList<CD>* slt = new TableSortedList<CD>(&CD::compare_items, &CD::compare_keys);
//DO THIS
//thoroughly test your table
ListArrayIterator<CD>* iter = cds->iterator();
String* titles[310];
CD* cds2[310];
int count = 0;
CD* duplicateTest; // test duplicate CD to be added later
while(iter->hasNext())
{
CD* cd = iter->next();
duplicateTest = cd;
cds2[count]=cd;
titles[count]=cds2[count]->getKey();
count++;
slt->tableInsert(cd);
}
delete iter;
slt->tableInsert(duplicateTest); // Program should not insert this CD because it is a duplicate
cout << "Table size after inserting all CDs is " << slt->tableSize() << endl; // If insert works correctly, size should be 310 (If duplicate was added, it would be 311)
for(count = 0; count < 310; count++)
{
CD* cdRetrieve = slt->tableRetrieve(titles[count]); // testing the retrieve function, it should be able to find all 310 CDs
if (cdRetrieve == NULL)
cout << "Couldn't find CD" << endl;
else
cout << "Found CD #" << count+1 << endl;
}
count = 1;
ListDoublyLinkedIterator<CD>* iter2 = slt->iterator(); // Testing the SLDL iterator, every CD should be displayed
while(iter2->hasNext())
{
CD* cd3 = iter2->next();
cout << "\nThis is CD #" << count << ":" << endl << endl;
count++;
cd3->displayCD();
}
for(int i = 0; i < 310; i++)
{
slt->tableRemove(titles[i]);
}
cout << "Table size after removing all CDs is " << slt->tableSize(); // Table size should be 0 after removing everything
deleteCDs(cds);
delete cds;
delete slt;
return 0;
}