0

Hashtable c++

I have a code for hashtable. When I add less than 6 keys, The program works normally. But when i add> 6 key , it’s will exception on visual studio or no output on sololearn and codeblock. I don't know why, can you help me? https://code.sololearn.com/cz1bXdMOlaBd/?ref=app https://code.sololearn.com/c5SrykWl66c4/?ref=app

1st Jun 2019, 1:21 PM
Dang Van Nhan
Dang Van Nhan - avatar
2 Answers
+ 4
I don't know how experienced you are in C++ but something like "vector<HASH_NODE*>** hashTable = new vector<HASH_NODE*>*[capacity];" even makes me nauseous. You know you can do something like vector<vector<HASH_NODE*>> if you need a 2d vector. There are just too many things that can go wrong if you use (type)**. Anyway, for some reason your hashTable[hash] points to some weird memory location: 0x616e616e6162, which doesn't look right. Accessing that 'invalid' memory region with hashTable[hash]->size() causes a crash. How it becomes 0x616e616e6162? Probably because ** are a nightmare to deal with. You can just put std::cout << __PRETTY_FUNCTION__ << " start\n"; and std::cout << __PRETTY_FUNCTION__ << " end\n"; at the beginning and end of each function. If the function name + end is never printed you know it crashes somewhere there. Or just use a debugger.
1st Jun 2019, 1:47 PM
Dennis
Dennis - avatar
0
I'm just a student, thank you for the experience of checking errors by cout the << "pretty function" at the beginning and end of each function. I didn't think about it
1st Jun 2019, 1:54 PM
Dang Van Nhan
Dang Van Nhan - avatar