I want to create an array of pointers, for my class. Each pointer will in fact be the 'head' of a dynamic list. I don't know the size of the array and it has to be given by the user.
So my problem is that in my class I have to read the size in the constructor. In the other functions of the class( e.g. insert etc.) the table has to EXIST. However, when I try to access it from the other functions (e.g. insert) the table isn't NULL. And the program crashes. Are there any solutions?
Here is a picture of what I want to create:
Here is the code:
So my problem is that in my class I have to read the size in the constructor. In the other functions of the class( e.g. insert etc.) the table has to EXIST. However, when I try to access it from the other functions (e.g. insert) the table isn't NULL. And the program crashes. Are there any solutions?
Here is a picture of what I want to create:
Here is the code:
Code:
#ifndef hashdef
#define hashdef
using namespace std;
class hash
{
int i;
int size;
class hash *table[ ];
public:
hash();
void insert(int a);
void deletekey(int key);
bool search(int a);
void destroy();
};
hash::hash()
{
cout<<"Give size:";
scanf("%d",&size);
class hash * table[size];
for(i=0;i<size;i++)
table[i]=NULL;
}
void hash::insert(int a)
{
if(a[0]==NULL)
cout<<"it's null"<<endl;
}
Comment