I'm trying to write a deck to use in a blackjack game, but am having trouble with the adding cards functions. After I add all of them, I traversed the list to check what's wrong, and for each card I print out the mpPrevious, mValue, mSuit, and mpNext. The Suit, Value, and Next card pointer are all fine, but the Previous member pointer is always 0 (null), instead of being the address of the previous card. Please help me find what is wrong...
Thank you,
Sean Michael Simonsen
Code:
void Deck::AddCardToTop( Card* pNewCard )
{
++mNumberOfCards;
if( !mpBottomCard )
{
mpBottomCard = pNewCard;
mpTopCard = pNewCard;
}
else
{
Card* Temp = mpTopCard;
mpTopCard = pNewCard;
mpTopCard->mpNext = Temp;
Temp->mpPrevious = mpTopCard;
}
}
void Deck::AddCardToBottom( Card* pNewCard )
{
++mNumberOfCards;
if( !mpTopCard )
{
mpBottomCard = pNewCard;
mpTopCard = pNewCard;
}
else
{
Card* Temp = mpBottomCard;
mpBottomCard = pNewCard;
mpBottomCard->mpPrevious = Temp;
Temp->mpNext = mpBottomCard;
}
}