Код: Выделить всё
Linear:
Hash table size: 8087
Number of collisions with a = 33: 6240629
Hash table size: 8087
Number of collisions with a = 37: 4817906
Hash table size: 8087
Number of collisions with a = 39: 6686453
Hash table size: 8087
Number of collisions with a = 41: 7423747Quadratic:
Hash table size: 8087
Number of collisions with a = 33: 1145326
Hash table size: 8087
Number of collisions with a = 37: 1182048
Hash table size: 8087
Number of collisions with a = 39: 1127766
Hash table size: 8087
Number of collisions with a = 41: 1152208
Instead, I get the following result for my output.
Hash table size : 8087
Number of collisions with a = 33: 1134428
Hash table size : 8087
Number of collisions with a = 37: 1166882
Hash table size : 8087
Number of collisions with a = 39: 1184105
Hash table size : 8087
Number of collisions with a = 41: 1159074
Код: Выделить всё
#include
#include
#include
#include
#include
#include "HashType - Copy.h"
using namespace std;
void buildHashTable(ifstream &inFile,
HashType &hashTable,
int type,
int Prime)
{
string word;
int length;
if (inFile.is_open())
{
while (inFile >> word)
{
length = word.size();
for (int i = 0; i < length;)
{
unsigned char ch = word[i]; // Cast to unsigned char to handle characters safely
if (ch < ' ' || ispunct(ch))
{ // Check for control characters and punctuation
word.erase(i, 1);
length = word.length(); // Update length after modifying the string
}
else
{
++i; // Only increment if no deletion was made
}
}
if (type == 1)
{
hashTable.InsertItemLinear(word, Prime);
}
if (type == 0)
{
hashTable.InsertItemQuadratic(word, Prime);
}
}
}
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/78422598/not-sure-why-quadratic-probing-wont-work-to-resolve-collisions-when-hashing[/url]