mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
remove pauses
This commit is contained in:
parent
b3cd53b26c
commit
9c5f853752
@ -10,9 +10,14 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace { // keep the code local to this file by assigning them to an unnamed
|
/**
|
||||||
// namespace
|
* @addtogroup open_addressing Open Addressing
|
||||||
|
* @{
|
||||||
|
* @namespace double_hashing
|
||||||
|
* @brief An implementation of hash table using [double
|
||||||
|
* hashing](https://en.wikipedia.org/wiki/Double_hashing) algorithm.
|
||||||
|
*/
|
||||||
|
namespace double_hashing {
|
||||||
// fwd declarations
|
// fwd declarations
|
||||||
using Entry = struct Entry;
|
using Entry = struct Entry;
|
||||||
bool putProber(const Entry& entry, int key);
|
bool putProber(const Entry& entry, int key);
|
||||||
@ -230,10 +235,17 @@ void removalInfo(int key) {
|
|||||||
std::cout << "New table: ";
|
std::cout << "New table: ";
|
||||||
display();
|
display();
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace double_hashing
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
using double_hashing::Entry;
|
||||||
|
using double_hashing::table;
|
||||||
|
using double_hashing::totalSize;
|
||||||
|
|
||||||
/** Main program
|
/** Main program
|
||||||
* @returns None
|
* @returns 0 on success
|
||||||
*/
|
*/
|
||||||
int main() {
|
int main() {
|
||||||
int cmd = 0, hash = 0, key = 0;
|
int cmd = 0, hash = 0, key = 0;
|
||||||
@ -242,7 +254,6 @@ int main() {
|
|||||||
table = std::vector<Entry>(totalSize);
|
table = std::vector<Entry>(totalSize);
|
||||||
bool loop = true;
|
bool loop = true;
|
||||||
while (loop) {
|
while (loop) {
|
||||||
system("pause");
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << "PLEASE CHOOSE -" << std::endl;
|
std::cout << "PLEASE CHOOSE -" << std::endl;
|
||||||
std::cout << "1. Add key. (Numeric only)" << std::endl;
|
std::cout << "1. Add key. (Numeric only)" << std::endl;
|
||||||
@ -256,18 +267,18 @@ int main() {
|
|||||||
case 1:
|
case 1:
|
||||||
std::cout << "Enter key to add = ";
|
std::cout << "Enter key to add = ";
|
||||||
std::cin >> key;
|
std::cin >> key;
|
||||||
addInfo(key);
|
double_hashing::addInfo(key);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
std::cout << "Enter key to remove = ";
|
std::cout << "Enter key to remove = ";
|
||||||
std::cin >> key;
|
std::cin >> key;
|
||||||
removalInfo(key);
|
double_hashing::removalInfo(key);
|
||||||
break;
|
break;
|
||||||
case 3: {
|
case 3: {
|
||||||
std::cout << "Enter key to search = ";
|
std::cout << "Enter key to search = ";
|
||||||
std::cin >> key;
|
std::cin >> key;
|
||||||
Entry entry = table[doubleHash(key, true)];
|
Entry entry = table[double_hashing::doubleHash(key, true)];
|
||||||
if (entry.key == notPresent) {
|
if (entry.key == double_hashing::notPresent) {
|
||||||
std::cout << "Key not present";
|
std::cout << "Key not present";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -275,10 +286,11 @@ int main() {
|
|||||||
case 4:
|
case 4:
|
||||||
std::cout << "Enter element to generate hash = ";
|
std::cout << "Enter element to generate hash = ";
|
||||||
std::cin >> key;
|
std::cin >> key;
|
||||||
std::cout << "Hash of " << key << " is = " << hashFxn(key);
|
std::cout << "Hash of " << key
|
||||||
|
<< " is = " << double_hashing::hashFxn(key);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
display();
|
double_hashing::display();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
loop = false;
|
loop = false;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup Open Addressing
|
* @addtogroup open_addressing Open Addressing
|
||||||
* @{
|
* @{
|
||||||
* @namespace linear_probing
|
* @namespace linear_probing
|
||||||
* @brief An implementation of hash table using [linear
|
* @brief An implementation of hash table using [linear
|
||||||
@ -228,8 +228,6 @@ int main() {
|
|||||||
table = std::vector<Entry>(totalSize);
|
table = std::vector<Entry>(totalSize);
|
||||||
bool loop = true;
|
bool loop = true;
|
||||||
while (loop) {
|
while (loop) {
|
||||||
std::cout << "\nPress a key to continue...\n";
|
|
||||||
std::cin.get();
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << "PLEASE CHOOSE -" << std::endl;
|
std::cout << "PLEASE CHOOSE -" << std::endl;
|
||||||
std::cout << "1. Add key. (Numeric only)" << std::endl;
|
std::cout << "1. Add key. (Numeric only)" << std::endl;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup Open Addressing
|
* @addtogroup open_addressing Open Addressing
|
||||||
* @{
|
* @{
|
||||||
* @namespace quadratic_probing
|
* @namespace quadratic_probing
|
||||||
* @brief An implementation of hash table using [quadratic
|
* @brief An implementation of hash table using [quadratic
|
||||||
@ -250,8 +250,6 @@ int main() {
|
|||||||
table = std::vector<Entry>(totalSize);
|
table = std::vector<Entry>(totalSize);
|
||||||
bool loop = true;
|
bool loop = true;
|
||||||
while (loop) {
|
while (loop) {
|
||||||
std::cout << "\nPress a key to continue...\n";
|
|
||||||
std::cin.get();
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << "PLEASE CHOOSE -" << std::endl;
|
std::cout << "PLEASE CHOOSE -" << std::endl;
|
||||||
std::cout << "1. Add key. (Numeric only)" << std::endl;
|
std::cout << "1. Add key. (Numeric only)" << std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user