1
写,没有实现对学生的滚动哈希函数的程序,并在他们的家庭进行分类。就像5000423,最后2位数字23,2 + 3 = 5,所以属于家族5
我尝试:捕获
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
const int tablesize= 20;
class hashentry
{
public:
int key;
int value;
hashentry(int key,int value)
{
this->key=key;
this->value=value;
}
};
class hashmap
{
public:
hashentry **table;
public:
hashmap()
{
int table=new hashentry *[tablesize];
for(int i=0;i<tablesize;i++)
{
table[i]=NULL;
}
}
int hashfunc(int key)
{
return key%tablesize;
}
void insert(int key, int value)
{
int hash=hashfunc(key);
while(table[hash]!=NULL && table[hash]->key!=key)
{
hash=hashfunc(hash+1);
}
table[hash]=new hashentry(key,value);
}
};
int main()
{
int key;
int value;
hashmap hash;
cout<<"enter value";
cin>>value;
cout<<"enter key at which element is to be inserted";
cin>>key;
hash.insert(key,value);
return 0;
}
错误:
In constructor 'hashmap::hashmap()':
invalid conversion from 'hashentry**' to 'int'
invalid types 'int[int]' for array subscript
猜测指针可能是你的程序中的一个'long' – Jay
'table'应该是构造函数中的'this.table' –
投票以打字方式结束。从构造函数中的int table = new hashentry * [tablesize];中移除int。 – NathanOliver