Using a structure with an array of structures
Before we implement the Shuffled
struct and operations on it, let's pause for a moment and reconsider how we might implement a shuffled deck. Because a deck of cards and a shuffled deck of cards are so similar, it makes somewhat more sense to combine them into a single structure, rather than have to declare and manipulate them separately. Our final Deck
structure will consist of two arrays – one of an ordered set of cards and another of pointers to cards in that deck, which can then be shuffled as needed. In one array, the Card
elements will always be ordered, while in the other array, the pointers can be swapped and moved around as needed. We will add additional information to the Deck
structure to keep track of whether the deck is shuffled and how many cards have been dealt.
As we enhance our Deck
structure and create/modify operations on the new structure, you should notice how little any of the other structures and methods...