Hello,
I have problem witch i've been working on for a couple of days now with no real progress. The problem is that i'm trying to search trough a array of pointer for a certain value. If the value exist return that value to be used in another function, but if it doesn't exist return NULL. It's a simple if else statement, but the else part is not working correctly. The problem is with the function " link* symbolTable::lookupArray(string value)". If the value is in the symbol table it works fine, but not if the value is not present. It compiles fine, but i get a error screen and have to close the window. I'm using ms visual studio. Here my code brief.
struct link
{
string data;
int token;
link *next;
};
class key
{
protected:
link *first;
public:
key (): first(NULL){}
~key () {} // destructor
void addTailItem (string);
void addHeadItem (string);
void findItem ();
void displayItem ();
void fillItem ();
int hashfunction (string); // hash value from string
};
class symbolTable : public key // replace keyword with key
{
private:
static const int MAX_LEX_ARRAY = 999; // size of lexeme array
static const int MAX_SYM_ARRAY = 9948; // size of symbol table array prime 9949
link *symbol[MAX_SYM_ARRAY]; // pointer table array
string lexemeArray[MAX_LEX_ARRAY]; // array holding the lexemes
public:
symbolTable() {}
void loadSymbol (); // add keywords to symbol table
link* lookupArray(string); // find function for symbol table
void insertArray (string); // insert function for symbol table
};
void symbolTable::loadSymbol()
{
cout<<":::loadsymboltable::: "<<endl;
link* current = first;
while(current != NULL)
{
if (current == NULL)
{
current = current->next->next;
}
symbol [hashfunction(current->data)]= current;
current = current ->next;
}
}
link* symbolTable::lookupArray(string value)
{
link* l;
for (l = symbol[hashfunction(value)]; l != NULL; l = l->next)
{
if (l->data == value)
{
return l;
}
else //THIS ELSE STATEMENT DOES NOT WORK
{
return NULL;
}
}
}
any help at all would be appreciated