使用模板的哈希表

时间:2018-12-14 14:21:58

标签: c++

我试图使用模板实现Hashtable,但出现错误,我的代码是:

 #include <iostream>
 #include <vector>
 using namespace std;

 template<class T>
  class Hash {
   int buckets;
   vector<T> *bucket_array;
public:
  Hash(int buck) { // always int.
   this->buckets = buck;
   bucket_array = new vector<T>[buck];
  }


void insertHash(T value) {
    int index = hashFunction(value);
    if(find(bucket_array[index].begin(), bucket_array[index].end(), value) != bucket_array.end()) {
      cout<<"Duplicates Cannot be stored !, Only Once.\n";
      return;
   }else
    bucket_array[index].push_back(value);
 }

这给出了错误-

error: member reference base type 'vector ' is not a structure or union
if(find(bucket_array[index].begin(), bucket_array[index].end(), value) 
!= bucket_array.end()) {

0 个答案:

没有答案