Hash Table with Chaining Assistance

I made a similar post to other sites, but did not really get any help, so I added more info and coded more of my own functions. I was given an assignment in which we need to implement a hashTable.h file and SLL.h (singly linked list) to complete project of taking in input from files ranging up to 750,000 elements and being able to search, delete, or input using the hash table. I am struggling however to make sure my SLL.h file is correctly coded to work with my hashTable.h, with the correctness of my hashTable.h, and my main project file. I coded my SLL.h file just fine and tested it Here are the three files:

I believe I coded my SLL.h class to my professors specifications, however I am struggling to code the hashTable.h file and correctly utilize my SLL.h in that code. I attempted to code most of it except the erase function, and it does not produce the correct results. By incorrect results I mean that the insert function did not increase the table size correctly I do not believe, and the search function I just could not figure out how to correctly code but I left in my attempts. Also in main I'm not sure if I'm calling the insert command correctly. Shouldn't it something like (table[key#])->insert(ssn, numD), because I tried that and the program crashed and the VC++ debug said it was an access violation. Any advice at all would be greatly appreciated, sorry for this wall of code, thank you in advance. (left out parts of code with didn't relate to my problems)
Last edited on
I'm a bit confused as to why you're using both a singly linked list && a hash-table. Either structure could hold the data by itself, what benefit does using both together provide and is it explicitly mentioned in your assignment that you have to have a hash-table with a singly linked list data-member? Just using SLL, say, find(), insert(), erase() could just as well have been SLL member methods
@gunnerfunner The professor included both the SLL.h and hashTable.h files and included all the headers, I just filled them with my code, so he does in fact want us to use both. I think that's why I've been struggling to find help online, I can't find anyone that has had to code a hash table with chaining like this.
Last edited on
The professor included both the SLL.h and hashTable.h files and included all the headers ...
so he does in fact want us to use both

use both yes, but use them both together with SLL as a data-member of the hash-table? Probably yes, otherwise you wouldn't have done it but does seem strange to me and that's why searches have also proved barren
@gunnerfunner yea he did include that too. Any sort of advice towards like where I could look for an example related to this? I've been doing a lot of searching but I just can't seem to find help
One 'solution' (using the term v loosely) would be to just think of HashTable as a wrapper and implement the usual find(), insert(), erase() methods for singly linked lists wrapped around the HashTable::SLL scope. Just an idea, perhaps someone will have a better one
Also check out the usual C++ implementation of a hash-table viz. std::unordered_map and you'll see why my previous posts expressed surprise at your prof's approach
you can make, in crude terms..

linked_list_class hashtable[size];

hashtable[key].insert();

which lets you keep size modest, and handles collisions with a variable sized container that grows to accept all the hits on the same key.

A vector or just about anything else is better (faster) than a linked list, but professors gonna profess.

The built in c++ containers win but sometimes people are learning data structures, and you can't learn much from 4 lines of code that does it all for you.

Topic archived. No new replies allowed.