-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathmain.cpp
115 lines (92 loc) · 2.74 KB
/
main.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
//*****************************************************************************************************
//
// This program demonstrates the HashTable class by instantiating a hash table of Stock objects
// and performing it's methods.
//
// Other files required:
// 1. stock.h - header file for the Stock class (includes stock.cpp)
// 2. hashTable.h - header file for the HashTable class (includes htElement.h)
//
//*****************************************************************************************************
#include "hashTable.h"
#include "stock.h"
#include <iostream>
using namespace std;
//*****************************************************************************************************
void test(HashTable<Stock> &table, const Stock &itemToSearchAndRemove);
//*****************************************************************************************************
int main() {
HashTable<Stock> stockTable(10);
Stock google("Google", "GOOGL", 1500.50);
Stock apple("Apple", "AAPL", 140.30);
Stock microsoft("Microsoft", "MSFT", 220.10);
Stock tesla("Tesla", "TSLA", 420.69);
Stock amazon("Amazon", "AMZN", 3000.00);
Stock googleCopy(google);
Stock amazonCopy("Amazooooon", "AMZN", 9999.00);
stockTable.insert(google);
stockTable.insert(apple);
stockTable.insert(microsoft);
stockTable.insert(tesla);
stockTable.insert(amazon);
stockTable.insert(googleCopy); // collision (not inserted)
stockTable.insert(amazonCopy); // collision (not inserted)
stockTable.display();
test(stockTable, apple); // found/removed
test(stockTable, apple); // not found/not removed
return 0;
}
//*****************************************************************************************************
void test(HashTable<Stock> &table, const Stock &item) {
Stock *searchResult = table.search(item);
cout << "\nSearching for " << item.getSymbol() << ":" << endl;
if (searchResult) {
cout << "Stock found!\n"
<< *searchResult << endl;
delete searchResult;
searchResult = nullptr;
table.remove(item);
cout << "\nAfter Removal of " << item.getSymbol() << ":" << endl;
table.display();
} else {
cerr << "Stock not found!\n";
}
}
//*****************************************************************************************************
/*
Amazon
AMZN
3000
Microsoft
MSFT
220.1
Google
GOOGL
1500.5
Apple
AAPL
140.3
Tesla
TSLA
420.69
Searching for AAPL:
Stock found!
Apple
AAPL
140.3
After Removal of AAPL:
Amazon
AMZN
3000
Microsoft
MSFT
220.1
Google
GOOGL
1500.5
Tesla
TSLA
420.69
Searching for AAPL:
Stock not found!
*/