• 11-10-2002
SeanMSimonsen
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;         } }```
• 11-10-2002
kuphryn
I recommend STL.

Kuphryn
• 11-10-2002
SeanMSimonsen
Thank you, I fixed it. The problem was not in those functions, but elsewhere. The reason I thought the previous pointers were null is because I kept printing them with respect to the Top Card, so it doesn't have a preceding one. I'm not using STL because it only does a void return type for removing nodes (as far as I know), and since it's a deck of cards I'll want to shuffle it using a real-life algorithm, plus I need the practice in making my own double linked list.
• 11-10-2002
kuphryn
Okay. You do not need to shuffle the deck. Use a randomized algorithm to access a node. In other words, you shuffle during the deal instead of before it.

Yes. You will gain experience.

Kuphryn