Week 4: Exercises

1. Hands of Cards

Consider this class:

enum Suit { Clubs, Diamonds, Hearts, Spades };

class Card {
    public int rank;    // 1 = Ace, 2 .. 10, 11 = Jack, 12 = Queen, 13 = King 
    public Suit suit;

    public Card(int rank, Suit suit) {
        this.rank = rank;
        this.suit = suit;
    }

}

a) Add a method string describe() that returns a string description such as "7 of Diamonds" or "Jack of Hearts".

b) Write a class Deck with these members:

2. Dynamic Array

Write a class DynArray that represents a variable-sized array of integers, with indices starting at 0. It should have the following members:

What will be the average-case big-O running time of append()?

3. Binary Tree

Write a class BinaryTree that holds a binary tree of integers. Your class should have these members: