Solved

Data structure for a deck of cards

Posted on 2011-03-01
5
843 Views
Last Modified: 2012-06-21
I am wondering if a stack would be the best data structure for a deck of cards.
The operations are addToDeck(), removeFromDeck() and shuffle().

Pleas let me know. Thanks!
0
Comment
Question by:dshrenik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 35014087
But probably in most operations you'll want to fetch the arbitrary
card from the deck - you'll not want first-in-first-out operations, so
maybe you'll not want to use Stack

Perhaps after all array will be better:

http://www.dreamincode.net/forums/topic/110380-deck-of-cards-using-various-methods/
0
 
LVL 84

Expert Comment

by:ozo
ID: 35014224
what do the operations addToDeck(), removeFromDeck() and shuffle() do?
what information does the deck contain?
0
 

Author Comment

by:dshrenik
ID: 35014231
addToDeck adds a card to the deck. removeFromDeck removes a card from the deck.
The deck is just a collection of orders in a particular order.
0
 
LVL 84

Expert Comment

by:ozo
ID: 35014338
When addToDeck adds a card, would it be the first card removed by removeFromDeck?
Would it be the last card removed by removeFromDeck?
Does addToDeck specify the value of the card to be added?
Does it specify the position in the deck where it is to be added?
Does removeFromDeck specify the value of the card to be removed?
Does it specify a position in the deck where a card is to be removed?
Does it remove the lowest value?  The highest value? Does it remove a random value?
When it removes a card from the deck, does it report what card was removed?
Does it report how many cards remain?
What happens if you try to remove from an empty deck?
What happens if you try to add a card that is already in the deck?
Would we be guaranteed that that never happens?

The answers to these questions should give you a better idea what would be the best data structure.
You might also consider:
Would calls to addToDeck and  removeFromDeck tend to alternate?
Would they tend to cluster?
How often is  shuffle() called compared to how often addToDeck and  removeFromDeck are called?
How many times can addToDeck be called?
How many decks can there be?
How hard should it be to predict the order after a shuffle()?


0
 

Author Comment

by:dshrenik
ID: 35014652
Thank you!
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JDBC performance 8 35
Find out all repos that a user is most active on Github 1 58
.NET Core supports which cell phone platforms? 3 38
Overriding a method 3 14
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question