I have this Java class:
class Card
{
private Suit suit;
private int rank;
}
(Suit
is an enum)
There are four suits with ranks 1-9 each and four suits with a single possible rank 0. Each card exists in an unknown but constant among all cards number of copies. How would I sort a deck in a set order of suits, and by increasing rank in each suit?
You'll need to either
compareTo
function that determines whether another card should be before or after this one in the sort orderand then you can use Collections.sort on your list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With