Implementing a deck of cards; considerations

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.



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

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store