The code below deletes the symbol associated with the stock object just fine. Its just bad object oriented design.
The way that i am searching for each stock symbol is by using a != or == test for NULL.
bool hashmap::remove(char const * const symbol, stock &s,
int& symbolHash, int& hashIndex, int& usedIndex)
{
if ( isAdded == 0 ) return false;
if ( hashTable[isRemoved].symbol == symbol ) return true;
else
{
symbolHash = this->hashStr( symbol );
hashIndex = symbolHash % maxSize;
usedIndex = hashIndex;
}
for ( int integer = 0; integer < maxSize; integer++ )
{
if ( hashTable[usedIndex].symbol != NULL &&
strcmp( hashTable[usedIndex].symbol, symbol ) == 0 )
{
isAdded--;
isRemoved = hashIndex;
s = &hashTable[usedIndex];
delete hashTable[usedIndex].symbol;
hashTable[usedIndex].symbol = NULL;
return true;
}
++usedIndex %= maxSize; // wrap around if needed
}
return false;
}
Im wondering now, if i delete in a such a way that:
hashTable[usedIndex].symbol = hashTable[NULL].symbol
Thereby, changing the way I logically test for an empty or found stock symbol. Is their a way to remove my stock symbol without having to redo the aspect of finding and searching?
Is this the correct way to remove in object oriented design?