Open and Closed Hashing in C
Again, I’m under the impression that you’ve done your assignment before coming here. I had this during my postgrad certification. Those were the bloody days that proved that my undergraduate years were nothing but a prelude to hell.
- Open: cells contain pointers to linked lists; collisions and a handful of inputs can be efficiently handled
/* point each cell to its respective (empty) Stack */ for(i = 0; i < MAX_VALUE; i++) { Stack *s = malloc(sizeof(Stack)); initStack(s); oh->cell[i] = s; }
- Closed: cells can contain two elements; makes use of a rehashing function to constantly search for an available cell when a collision occurs
for(i = 0; i < MAX_VALUE; i++) { for(j = 0; j < 2; j++) { ch->cell[i][j] = 0; } }
Input validation was kinda neglected (and I’m obviously not into adding them right now) so, children, refrain from inputting non-numeric keys, okay?