Question: Java problem using deque. Need help! One way to shuffle playing cards is to use a perfect shuffle . First, you divide a deck of

Java problem using deque. Need help!

One way to shuffle playing cards is to use a perfect shuffle. First, you divide a deck of 52 cards into two halves of 26 cards each. Next, you merge the halves by interleaving the cards as follows. Beginning with the top half and alternating halves, you take the bottom card from a half and place it on top of a new deck.

For example, if our deck contains the six cards 1 2 3 4 5 6, the top half is 1 2 3, and the bottom half is 4 5 6. The 3 at the bottom of the top half becomes the bottom card in the shuffled deck. We then place the 6, which is at the bottom of the bottom half, on top of the shuffled deck. Next, we place 2 on top, then 5, 1, and finally 4. The shuffled deck is then 4 1 5 2 6 3. Notice that the card that was on top of the original deck is now second in the shuffled result, and the bottom card in the original deck is now second from the bottom in the shuffled deck. This shuffle is called an in-shuffle and is achieved by beginning with the top half when you move cards into the shuffled result. If you begin with the bottom half, you get an out-shuffle, whereby the original top card and bottom card remain in their positions in the shuffled deck.

Define a class of playing-card decks by using a deque to contain the cards. Your class should define methods to perform perfect in-shuffles and perfect out-shuffles. Using your class,

a) Determine the number of perfect out-shuffles needed to return a deck of n cards to its original order.

b) Determine the number of perfect in-shuffles needed to return a deck of n cards to its original order.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!