【发布时间】:2015-10-19 21:26:39
【问题描述】:
如果我解释不清楚,请提前原谅.. 好的,所以我已经使用这样的向量声明了一个哈希表:
> class HashTable{
private:
vector<string> arrayofbuckets[100];
public:
void insertelement(string input);
void deleteelement(string remove);
bool lookupelement(string search);
int tablesize();
> }; // end of class
我还创建了一个使用 switch 语句将元素插入哈希表的菜单:
> case 'I':
{
cout << " Which element would you like to insert?: ";
cin >> Element;
hash.insertelement(Element);
}
break;
然后它被传递给这个函数:
void HashTable::insertelement(string input){
int hashValue = 0;
for(int i = 0; i<input.length(); i++){
hashValue = hashValue + int(input[i]);
}
hashValue = hashValue % 100;
arrayofbuckets[hashValue].push_back(input);
cout << " The element " << input << " has been put into value " << hashValue << ends;
}
有人知道如何编写一个函数来获取和显示表格的大小吗?
【问题讨论】: