If it's the responsibility of CardPtr
to always point at the top card (the start of the linked list), then this method's code should be changed so that it does not modify CardPtr
. Perhaps declare another local variable, initialize it to equal CardPtr
and then modify that pointer repeatedly in your loop (so that CardPtr
never changes).
It's also possible that your other method that deals a card from the top of the deck is not leaving CardPtr
in a good state (pointing at the new top card), which means you've got more than one problem to fix.