Unknown type name 'HashEntry' Error Message will not go away

Viewed 45

I am trying to write this code that will insert a list of numbers into a hash table. I'm having an issue where it gives me an error:

Unknown type name 'HashEntry'

This error shows up on two lines (indicated below).

I'm not sure what I need to do to satisfy this error message and be able to run my code. Can you please help me?

#include <iostream>
using namespace std;

const int TABLE_SIZE = 17;

class HashMap {
private:
    HashEntry *table;        //ERROR HERE !!

public:
    HashMap() {
        table = new HashEntry*[TABLE_SIZE];        //ERROR HERE !!
        for (int i = 0; i < TABLE_SIZE; i++)
            table[i] == NULL;
    }

    int get(int key) {
        int hash = (key % 17);

        while (table[hash] != NULL && table[hash] != key)
            hash = (hash + 1) % 17;

        if (table[hash] == NULL)
            return -1;
        else
            return table[hash];
    }

    void insert(int value) {
        int hash = (value % 17);

        if(get(value) == -1){
            table.push_back(value);
        }
        else if(get(value) != -1){
            table[hash] = value;
        }
    }

    ~HashMap() {
        for (int i = 0; i < 17; i++)
            if (table[i] != NULL)
                delete table[i];
        delete[] table;
    }
};

int main(int argc, const char * argv[])
{
    HashMap Kirsten;

    Kirsten.insert(121);
    Kirsten.insert(81);
    Kirsten.insert(16);
    Kirsten.insert(100);
    Kirsten.insert(25);
    Kirsten.insert(0);
    Kirsten.insert(1);
    Kirsten.insert(9);
    Kirsten.insert(4);
    Kirsten.insert(36);
    Kirsten.insert(64);
    Kirsten.insert(49);

    for(int i = 0; i < 12; i++){
        cout << Kirsten.get(i) << endl;
    }

    return 0;
}
0 Answers
Related