std::vector<Entry> table;
57 inthash =
static_cast<int>(
hashFxn(key));
62(hash +
static_cast<size_t>(std::round(std::pow(i, 2)))) %
66 if(entry.
key== notPresent) {
70std::cout <<
"Found key!"<< std::endl;
73std::cout <<
"Found tombstone or equal hash, checking next" 79std::cout <<
"Spot found!"<< std::endl;
84std::cout <<
"Spot taken, looking at next (next index = " 85<< (hash +
static_cast<size_t>(
86std::round(std::pow(i + 1, 2)))) %
92 if(i == totalSize * 100) {
93std::cout <<
"Quadratic probe failed (infinite loop)"<< std::endl;
96}
while(entry.
key!= notPresent);
107 if(entry.
key== notPresent || entry.
key== tomb) {
120 if(entry.
key== key) {
133 if(index == notPresent) {
143 for(
inti = 0; i < totalSize; i++) {
144 if(table[i].key == notPresent) {
145std::cout <<
" Empty ";
146}
else if(table[i].key == tomb) {
147std::cout <<
" Tomb ";
150std::cout << table[i].key;
154std::cout << std::endl;
163 intoldSize = totalSize;
164std::vector<Entry> oldTable(table);
167table = std::vector<Entry>(totalSize);
168 for(
inti = 0; i < oldSize; i++) {
169 if(oldTable[i].key != -1 && oldTable[i].key != notPresent) {
171 add(oldTable[i].key);
176std::cout <<
"Table was rehashed, new size is: "<< totalSize << std::endl;
184table[index].key = key;
186 if(++size /
static_cast<double>(totalSize) >= 0.5) {
196 if(index == notPresent) {
197std::cout <<
"key not found"<< std::endl;
199table[index].key = tomb;
200std::cout <<
"Removal successful, leaving tombstone"<< std::endl;
208std::cout <<
"Initial table: ";
210std::cout << std::endl;
211std::cout <<
"hash of "<< key <<
" is "<<
hashFxn(key) <<
" % " 212<< totalSize <<
" == "<<
hashFxn(key) % totalSize;
213std::cout << std::endl;
215std::cout <<
"New table: ";
223std::cout <<
"Initial table: ";
225std::cout << std::endl;
226std::cout <<
"hash of "<< key <<
" is "<<
hashFxn(key) <<
" % " 227<< totalSize <<
" == "<<
hashFxn(key) % totalSize;
228std::cout << std::endl;
230std::cout <<
"New table: ";
240usingquadratic_probing::table;
241usingquadratic_probing::totalSize;
247 intcmd = 0, key = 0;
248std::cout <<
"Enter the initial size of Hash Table. = ";
249std::cin >> totalSize;
250table = std::vector<Entry>(totalSize);
253std::cout << std::endl;
254std::cout <<
"PLEASE CHOOSE -"<< std::endl;
255std::cout <<
"1. Add key. (Numeric only)"<< std::endl;
256std::cout <<
"2. Remove key."<< std::endl;
257std::cout <<
"3. Find key."<< std::endl;
258std::cout <<
"4. Generate Hash. (Numeric only)"<< std::endl;
259std::cout <<
"5. Display Hash table."<< std::endl;
260std::cout <<
"6. Exit."<< std::endl;
264std::cout <<
"Enter key to add = ";
269std::cout <<
"Enter key to remove = ";
274std::cout <<
"Enter key to search = ";
279 if(entry.
key== quadratic_probing::notPresent) {
280std::cout <<
"Key not present";
285std::cout <<
"Enter element to generate hash = ";
287std::cout <<
"Hash of "<< key
298std::cout << std::endl;
An implementation of hash table using quadratic probing algorithm.
void removalInfo(int key)
int quadraticProbe(int key, bool searching)
bool putProber(const Entry &entry, int key)
bool searchingProber(const Entry &entry, int key)
Entry(int key=notPresent)
constructor
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4