#include <stdio.h>
#define TABLE_SIZE 10
int hashTable[TABLE_SIZE];
int occupied = 0;
/* Initialize hash table */
void initialize() {
for (int i = 0; i < TABLE_SIZE; i++) {
hashTable[i] = -1;
}
}
/* Insert key using linear probing */
int insertKey(int key) {
if (occupied == TABLE_SIZE) {
printf("Hash table is full\n");
return 1;
}
int index = key % TABLE_SIZE;
/* Linear probing */
while (hashTable[index] != -1) {
index = (index + 1) % TABLE_SIZE;
}
hashTable[index] = key;
occupied++;
return 0;
}
/* Display hash table */
void display() {
for (int i = 0; i < TABLE_SIZE; i++) {
if (hashTable[i] == -1)
printf("[%d] : EMPTY\n", i);
else
printf("[%d] : %d\n", i, hashTable[i]);
}
}
int main() {
initialize();
insertKey(12);
insertKey(22);
insertKey(32);
insertKey(42);
insertKey(52);
display();
return 0;
}