mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
use named namespace
This commit is contained in:
parent
e09637fb30
commit
a8b2825403
@ -9,9 +9,14 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace { // keep the code local to this file by assigning them to an unnamed
|
/**
|
||||||
// namespace
|
* @addtogroup Open Addressing
|
||||||
|
* @{
|
||||||
|
* @namespace linear_probing
|
||||||
|
* @brief An implementation of hash table using [linear
|
||||||
|
* probing](https://en.wikipedia.org/wiki/Linear_probing) algorithm.
|
||||||
|
*/
|
||||||
|
namespace linear_probing {
|
||||||
// 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);
|
||||||
@ -204,7 +209,11 @@ void removalInfo(int key) {
|
|||||||
std::cout << "New table: ";
|
std::cout << "New table: ";
|
||||||
display();
|
display();
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace linear_probing
|
||||||
|
|
||||||
|
using linear_probing::Entry;
|
||||||
|
using linear_probing::table;
|
||||||
|
using linear_probing::totalSize;
|
||||||
|
|
||||||
/** Main function
|
/** Main function
|
||||||
* @returns 0 on success
|
* @returns 0 on success
|
||||||
@ -216,7 +225,8 @@ 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 << "\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;
|
||||||
@ -230,18 +240,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);
|
linear_probing::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);
|
linear_probing::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[linearProbe(key, true)];
|
Entry entry = table[linear_probing::linearProbe(key, true)];
|
||||||
if (entry.key == notPresent) {
|
if (entry.key == linear_probing::notPresent) {
|
||||||
std::cout << "Key not present";
|
std::cout << "Key not present";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -249,10 +259,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 = " << linear_probing::hashFxn(key);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
display();
|
linear_probing::display();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
loop = false;
|
loop = false;
|
||||||
|
@ -250,7 +250,8 @@ 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 << "\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