Implement a Map using Hash Tables, program keeps crashing.

Hello,

I'm trying to create a function that returns true or false if a key is inside a map.

My code keeps crashing at line 11 for some reason.

My private variable is vector<list<Entry > >table;

The code in class Entry is pretty much just to act like a pair. So the private variables are
1
2
string key;
int value;


My current code for the function is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
bool MyMap::containsKey(const string& key){

    //Find out which bucket to start searching from.
    int bucket = hash(key);

    //Make a list in order to search through.
    list<Entry>& listToSearch = table[bucket];

    list<Entry>::const_iterator iter;

    iter = listToSearch.begin();  // <- Causes my program to crash.

    return false;
}


what seems to be the problem?
Thank You
Last edited on
Try using table.at(bucket) (in place of table[bucket]) so that you will get an exception if bucket is out-of-bounds.
Last edited on
Hey, I took your advice and it gave me the out of bounds exception. Guess I messed up somewhere else, thank you.
Topic archived. No new replies allowed.