Initializing a hash table structure in a class

So I have an assignment where I have to make a hash table and I can't seem to get past the first part of allocating space for it and setting all the addresses equal to NULL.

Here is my header file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    #ifndef _CONGERA6H_H
    #define _CONGERA6H_H

    const int MAX_STRING = 80;
    typedef char Element300[MAX_STRING + 1];

    class HT300
    {
    public:
        HT300(const int);
        ~HT300();
        void search300(const Element300);
        void view300() const;
    private:
        const int MAX_TABLE;
        struct HTNode300
        {
            Element300 reserved;
            int hashed, probed, matched;
        };
        HTNode300 * theTable;
        HT300();
        HT300(const HT300 &);
        int hash300(const Element300) const;
        void create300();
        void fill300();
    };

    #endif 


And here is the functions in my implementation file that are relevant to the question.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    #include <iostream>
    #include <cstring>
    #include <fstream>
    #include "congera6h.h"
    using namespace std;

    HT300::HT300(const int size) : MAX_TABLE(size)
    {
        theTable = new HTNode300[size];
        create300();
    }

    void HT300::create300()
    {
        While (theTable
        strcpy(aTable, '\0');

    }


I'm not sure if I'm even setting the table up correctly in the constructor. I know for a fact that we have to use a new operator in the constructor and then initialize all the addresses to NULL in the create300 function.
I'm not sure if I'm even setting the table up correctly in the constructor.
It's correct.

To initialize theTable use another constructor:
1
2
3
4
5
6
7
8
9
10
        struct HTNode300
        {
            Element300 reserved;
            int hashed, probed, matched;

            HTNode300() : hashed(0), probed(0), matched(0)
            {
              reserved[0] = 0;
            }
        };
With this you don't need create300().
Topic archived. No new replies allowed.