我正在关注一些关于使用单独链接实现哈希表的手写笔记。特别是我正在寻找这个功能:
list<ListCell>::iterator TablaHash::FoundOnList(int key, int table_row){
for(list<ListCell>::iterator found= table[table_row].begin();
found != table[table_row].end();found++){
if((*found).Key() == key){
return found;
}
}
return Ø;
}
最后一个符号是空集。我知道我应该在那里返回一个“空”迭代器,但我该怎么办?也许返回 end() 迭代器?
最佳答案
是的,返回 end()
迭代器是 C++ 中最自然的事情。
例如,std::find
如果找不到所搜索的项目,则返回 end
迭代器。
关于c++ - 在 C++ 哈希表代码中返回空迭代器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31774484/