next up previous
Next: Merge Up: Assignment 12: 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.8. You can use the randInt method from the solutions to Homework 11. 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 low to high, including both).

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



Allen B. Downey
1999-04-28