Linear Probing
Linear Probing
class LinearProbingHashTable {
private:
int* table; // Hash table array
int tableSize; // Size of the hash table
int numElements; // Number of elements in the hash table
public:
// Constructor to initialize the hash table with the given size
LinearProbingHashTable(int size) {
tableSize = size;
table = new int[tableSize];
for (int i = 0; i < tableSize; i++) {
table[i] = -1; // Initialize the table with -1 (empty slots)
}
numElements = 0;
}
table[index] = key;
numElements++;
cout << "Inserted key " << key << " at index " << index << endl;
}
int main() {
int size, numKeys, key;