TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
quadratic_probing_hash_table.cpp File Reference

Storage mechanism using quadratic probing hash keys. More...

#include <cmath>
#include <iostream>
#include <vector>
Include dependency graph for quadratic_probing_hash_table.cpp:

Go to the source code of this file.

Classes

struct  quadratic_probing::Entry
 

Namespaces

namespace  quadratic_probing
 An implementation of hash table using quadratic probing algorithm.
 

Functions

bool quadratic_probing::putProber (const Entry &entry, int key)
 
bool quadratic_probing::searchingProber (const Entry &entry, int key)
 
void quadratic_probing::add (int key)
 
size_t quadratic_probing::hashFxn (int key)
 
int quadratic_probing::quadraticProbe (int key, bool searching)
 
Entry quadratic_probing::find (int key)
 
void quadratic_probing::display ()
 
void quadratic_probing::rehash ()
 
void quadratic_probing::remove (int key)
 
void quadratic_probing::addInfo (int key)
 
void quadratic_probing::removalInfo (int key)
 
int main ()
 

Variables

int quadratic_probing::notPresent
 
std::vector< Entryquadratic_probing::table
 
int quadratic_probing::totalSize
 
int quadratic_probing::tomb = -1
 
int quadratic_probing::size
 
bool quadratic_probing::rehashing
 

Detailed Description

Storage mechanism using quadratic probing hash keys.

Author
achance6
Krishna Vedala
Note
The implementation can be optimized by using OOP style.

Definition in file quadratic_probing_hash_table.cpp.

Function Documentation

◆ main()

int main ( void )

Main function

Returns
None

Definition at line 246 of file quadratic_probing_hash_table.cpp.

246 {
247 int cmd = 0, hash = 0, key = 0;
248 std::cout << "Enter the initial size of Hash Table. = ";
249 std::cin >> totalSize;
250 table = std::vector<Entry>(totalSize);
251 bool loop = true;
252 while (loop) {
253 std::cout << std::endl;
254 std::cout << "PLEASE CHOOSE -" << std::endl;
255 std::cout << "1. Add key. (Numeric only)" << std::endl;
256 std::cout << "2. Remove key." << std::endl;
257 std::cout << "3. Find key." << std::endl;
258 std::cout << "4. Generate Hash. (Numeric only)" << std::endl;
259 std::cout << "5. Display Hash table." << std::endl;
260 std::cout << "6. Exit." << std::endl;
261 std::cin >> cmd;
262 switch (cmd) {
263 case 1:
264 std::cout << "Enter key to add = ";
265 std::cin >> key;
267 break;
268 case 2:
269 std::cout << "Enter key to remove = ";
270 std::cin >> key;
272 break;
273 case 3: {
274 std::cout << "Enter key to search = ";
275 std::cin >> key;
277 quadratic_probing::table[quadratic_probing::quadraticProbe(
278 key, true)];
279 if (entry.key == quadratic_probing::notPresent) {
280 std::cout << "Key not present";
281 }
282 break;
283 }
284 case 4:
285 std::cout << "Enter element to generate hash = ";
286 std::cin >> key;
287 std::cout << "Hash of " << key
288 << " is = " << quadratic_probing::hashFxn(key);
289 break;
290 case 5:
292 break;
293 default:
294 loop = false;
295 break;
296 // delete[] table;
297 }
298 std::cout << std::endl;
299 }
300 return 0;
301}
void * hash(const std::string &message)
Converts the string to bytestring and calls the main algorithm.
Definition md5.cpp:288
int quadraticProbe(int key, bool searching)
int key
key value