Hi all,
So I'm currently teaching myself about hash tables. I'm doing a programming challenge where I create a hash table that stores instances of a class Person, with data members for name, phone number, and GPA. The table uses separate chaining to take care of collisions. The node I'm using for this is called hashNode.
The error that I'm getting is one that I have never seen before. I've searched around the internet, but it appears to be quite rare in this sort of situation.
The error message is 'error: base operand of '->' has non-pointer type 'hashNode''. This error occurs every single time that I use the arrow operator with the hashNode.
This has me really baffled, since there appears to be no difference between this case and all the other times I have used such a node with a linked list.
The code for the hash table below is a work in progress, and not all of the necessary functions have been implemented, but I am hesitant to move forward with this error still cropping up.
person.h contains the Person class
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <string>
using namespace std;
class Person{
private:
string name;
string phonenumber;
string GPA;
public:
Person();
Person(string name, string phonenumber);
string getName();
string getPhonenumber();
void setName(string newname);
void setPhonenumber(string newphonenumber);
void setGPA(string);
string getGPA();
};
hash.h contains the hashTable class
#include <string>
#include <iostream>
//#include "ChainNode.h"
#include "person.h"
#define MAX 200
using namespace std;
struct hashNode
{
Person data;
bool filled;
hashNode * next;
};//end node
class hashTable {
private:
hashNode array[MAX];
public:
int hash(string);
void prepArray();
void tableInsert(Person p);
void tableDelete(string);
};//end hashTable
void hashTable::tableDelete(string phonenumber)
{
int index = hash(phonenumber);
}
void hashTable::tableInsert(Person p)
{
int index = hash(p.getPhonenumber());
hashNode hp = array[index];//hashed position
if(hp.filled == false)
{
hp->data = p;
hp->filled = true;
hp->next->filled = false;
}
else if(hp.filled)
{
while(hp.filled)
{
hp = hp->next;
}//end while
//the first empty position has now been found
hp.data = p;
hp.filled = true;
hp->next.filled = false;
}//end else if
}//end tableInsert
void hashTable::prepArray()
{
for(int i = 0; i < MAX; i++)
{
array[i].filled = false;
}//end for
//all the filled tags are now set to false
}//end prepArray
int hashTable::hash(string phonenumber)
{
//string str = p.getPhonenumber();
//int size = str.size();
int size = phonenumber.size();
double sum;
for(int i=0; i < size; i++)
{
sum = phonenumber[i];
}//end for
}
If anybody could shed any light on this, it would be greatly appreciated.