PROGRAMMING ❤

Implementing a deck of cards; considerations

Al Hinds

--

A deck of cards for a game had a lot of student’s scratching their head — even when the appropriate data structures had been drilled into them for the previous few weeks. The problem here was connecting the dots. There are many correct possible ideas here, and that in itself is intimidating for newcomers.

What does a deck need to do?

  • An abstracted deck should hold a number of cards.
  • It should be simple to add and remove cards from the deck
  • It can hold order, but doesn’t have to. That is; order isn’t guaranteed.
  • The size is going to be dynamic and often changing (HINT: Don’t use an array).

Possible implementations:

There are tradeoffs with all of the above.

--

--

Al Hinds

Write about all sorts of stuff. Dev. Sport. Life.