-2

使用这个数据结构:(一个双向链表数组)

list<string> hashTable [HASH_TABLE_SIZE];

我想使用以下方法检查某个链接列表是否为空:

Hash HashTable;

if(Hash[hf(word)].empty() == true)
{do this}

这些是我得到的编译错误:

$ make -f makefile.txt
g++ -g -D HASH_TABLE_SIZE=10 -c hash.cpp
hash.cpp: In member function `void Hash::processFile(std::string)':
hash.cpp:19: error: expected primary-expression before '[' token
makefile.txt:6: recipe for target `hash.o' failed
make: *** [hash.o] Error 1
4

1 回答 1

0

首先你有编译错误。请显示您的 hash.cpp 文件的第 19 行。第二:

Hash[hf(word)].empty() == true

是一个不好的比较,你可以只使用

 if ( Hash[hf(word)].empty() )

第三:列表是一个动态结构,所以,我认为,最好使用指向列表的指针数组:

list<string> * hashTable[HASH_TABLE_SIZE]
于 2013-11-06T07:40:13.947 回答