Can this code be modified for hash usage
Jan 30, 2014 at 2:29pm UTC
Hi Fellow programmers,
I was implementing hash map using ordered map. I was reading online about std::hash function and I did not know how to use it here. Can someone help?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
bool LinkedList::checkDuplicates(){
Node *prev, *leaf;
std::unordered_map<int , Node*> hash;
prev = head;
leaf = head->next;
while (leaf){
auto elem = hash.find(leaf->value);
if (elem == hash.end()){
hash.insert(std::pair<int , Node*>(leaf->value, leaf));
prev = leaf;
leaf=leaf->next;
}
else {
cout << "Duplicate element found" << endl;
prev->next = leaf->next;
delete leaf;
return true ;
}
}
}
Jan 30, 2014 at 4:22pm UTC
Topic archived. No new replies allowed.