c++ - 在 C++ 哈希表代码中返回空迭代器

标签 c++ hash iterator hashtable isnullorempty

我正在关注一些关于使用单独链接实现哈希表的手写笔记。特别是我正在寻找这个功能:

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/

相关文章:

c++ - 在 ObjectPascal 中处理算术右移

c++ - Ifstream 从文本文件中获取信息

c++ - std::sort 在 c 风格的字符串上,不复制字符串

c++ - 更改指针后,free() 将释放多少字节?

ruby - 如何仅基于键从哈希数组中删除重复项?

c++ - 在同一对象内插入 vector

ruby - File.open ('file.txt' ) 与 File.open ('file.txt' ).readlines

c - 什么是散列指针的最快、可移植的方法,我们知道指针与固定大小的 int 对齐?

powershell - 如何将 PowerShell 哈希对象打印为哈希对象?

scala - Traversable 是一个特征还是一个类