#include "map.h"
using std::cout;
using std::endl;
Map::Map ()
{
for (int i = 0;i <= 100;i++)
hashtable[i] = NULL;
}
Map::~Map()
{
for(int i=0;i<101;i++)
{
delete hashtable[i];
}
}
nlist * Map::Insert (int key,int newValue)
{
nlist *np = new nlist;
int hashval = 0;
hashval = hashFun (key);
np->value = newValue;
np->keys = key;
np->next = hashtable[hashval];
hashtable[hashval] = np;
return np;
}
nlist * Map::hashtable_search(int key)
{
nlist *np = new nlist;
while(np != NULL)
{
if (key == np->keys)
return np;
else
return NULL;
}
}
void Map::printfMap ()
{
nlist *np = new nlist;
for (int i =0;i<101;i++)
{
np = hashtable[i];
while (np )
{
std::cout<<np->keys<<"\t"<<np->value<<endl;
np = np->next;
}
}
}
int main()
{
Map m;
m.Insert (7,343);
m.Insert (3,56);
m.Insert (2,6);
m.Insert (4,65);
m.printfMap();
return 0;
}