next up previous
Next: Histograms of cards Up: Assignment 11: Arrays of Previous: Exercises from the book

Shuffling and sorting

1.
Write a method called swapCards that takes a deck (array of cards) and two indices, and that switches the cards at those two locations.

HINT: it should switch the references to the two cards, rather than the contents of the two objects. This is not only faster, but it makes it easier to deal with programs in which cards are aliased.

2.
Write a method called shuffleDeck that uses the algorithm in Section 12.1. You can use the randInt method from the solutions to Homework 10. Look it over carefully, it may be different from what you wrote.

3.
Write method called findLowestCard that uses the compareCard method to find the lowest card in a given range of the deck (from lowIndex to highIndex, including both).

4.
Write a method called sortDeck that arranges a deck of cards from lowest to highest.



Allen Downey
1999-11-16